背景

grafana是一个不错的监控软件,不仅能展示prometheus的数据,还能对接loki日志。但是呢,当loki日志量大的时候,传输延迟会增加,导致用户体验不好。

本文介绍容器化部署grafana并开启gzip压缩。

过程

容器部署

---
version: "3.3"

networks:
  prod:
    driver: bridge
    ipam:
      config:
        - subnet: 7.0.0.0/24

services:
  prometheus:
    build:
      context: ./prometheus
      dockerfile: Dockerfile
    image: swr.cn-north-4.myhuaweicloud.com/yunweitest/prometheus:20221010
    restart: always
    container_name: prometheus
    hostname: prometheus
    environment:
      - TZ=Asia/Shanghai
    networks:
      prod:
        ipv4_address: 7.0.0.11
    ports:
      - 9090:9090
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/usr/share/prometheus/console_libraries'
      - '--web.console.templates=/usr/share/prometheus/consoles'
      - '--storage.tsdb.retention.time=90d'
      - '--web.external-url=prometheus'
      - '--web.enable-admin-api'
      - '--web.enable-lifecycle'
    volumes:
      - /data/prometheus/:/etc/prometheus/
      - /data/promdata:/prometheus
cat <<'EOF'> /data/grafana/config/grafana.ini
[paths]
[server]
enable_gzip = true
[database]
[datasources]
[remote_cache]
[dataproxy]
[analytics]
[security]
[security.encryption]
[snapshots]
[dashboards]
time_options = 10s,30s,1m,5m,15m,1h,6h,12h,24h,2d,7d,30d
min_refresh_interval = 2s
[users]
[auth]
[auth.anonymous]
[auth.github]
[auth.gitlab]
[auth.google]
[auth.grafana_com]
[auth.azuread]
[auth.okta]
[auth.generic_oauth]
[auth.basic]
[auth.proxy]
[auth.jwt]
[auth.ldap]
[aws]
[azure]
[rbac]
[smtp]
[emails]
[log]
[log.console]
[log.file]
[log.syslog]
[log.frontend]
[quota]
[unified_alerting]
[unified_alerting.reserved_labels]
[alerting]
[annotations]
[annotations.dashboard]
[annotations.api]
[explore]
[help]
[profile]
[query_history]
[metrics]
[metrics.environment_info]
[metrics.graphite]
[grafana_com]
[tracing.jaeger]
[tracing.opentelemetry.jaeger]
[tracing.opentelemetry.otlp]
[external_image_storage]
[external_image_storage.s3]
[external_image_storage.webdav]
[external_image_storage.gcs]
[external_image_storage.azure_blob]
[external_image_storage.local]
[rendering]
[panels]
[plugins]
[live]
[plugin.grafana-image-renderer]
[enterprise]
[feature_toggles]
[date_formats]
[expressions]
[geomap]
EOF

注意

  • grafana前端如果要增加反向代理,则需要修改[server]配置栏目。
最后修改:2024 年 05 月 11 日
如果觉得我的文章对你有用,请随意赞赏