Traefik 2 监控系统之Grafana Prometheus Promtail Loki完美结合

背景

按上篇文章《Traefik 2 群晖硬核指南》,文章阐述了容器时代下如何替代Nginx,搭建一个基于Traefik 2,搭建自动SSL、容器自动服务注册、自动域名解析的统一网关,网关是搭建好了,我们还需要做服务监控,才能做到心中有数,有据可查。

本文以上篇文章为范本,再次全流程的介绍如何搭建Traefik、Grafana、Prometheus、Promtail、Loki,并且如何配置服务,实现自动化日志记录、监控。

效果图

二话不说,咱们先看效果吧。

监控大盘
监控大盘
日志检索
日志检索

Traefik

按上篇文章,我们已经搭建了Traefik,但为了配合监控,我们需要对docker-compose.yml进行改造,因此,本文从头到尾的写一遍,您只需要看这一篇文章就够了,部分内容可能描述不够详细,有疑惑请到上一篇文章阅读。

cd /volume1/docker/
mkdir traefik
cd traefik
mkdir config
mkdir ssl
# 创建traefik专属网络
docker network create traefik

亮出我们的利器,通过docker-compose启动,编辑刚刚创建的yml文件 docker-compose.yml

version: '3.7'

services:

  traefik:
    container_name: traefik
    environment:
      - CF_API_EMAIL=CLOUDFLARE邮箱
      - CLOUDFLARE_DNS_API_TOKEN=CLOUDFLARE API TOKEN
      - CLOUDFLARE_ZONE_API_TOKEN=CLOUDFLARE API TOKEN
    image: traefik:v2.1.3
    restart: always
    ports:
      - target: 52080
        published: 52080
        mode: host
      - target: 52443
        published: 52443
        mode: host
      - target: 52022
        published: 52022
        mode: host
      - "8080:8080"
    command: traefik --configFile /etc/traefik.yml
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./ssl/:/data/ssl/:rw
      - ./traefik.yml:/etc/traefik.yml:ro
      - ./config/:/etc/traefik/config/:ro
      - ./logs/:/data/logs/:rw
    healthcheck:
      test: ["CMD-SHELL", "wget -q --spider --proxy off localhost:8080/ping || exit 1"]
      interval: 6h
    network_mode: host


在根目录下新建文件traefik.yml,写入如下配置内容。

global:
  checkNewVersion: false
  sendAnonymousUsage: false

log:
  level: "WARN"
  format: "common"
  filePath: "/data/logs/traefik.log"

api:
  dashboard: true
  insecure: true

ping: {}

accessLog:
  filePath: "/data/logs/access.log"
  bufferingSize: 100
  format: json
  filters:    
    minDuration: "10ms"

providers:
  docker:
    watch: true
    exposedByDefault: false
    endpoint: "unix:///var/run/docker.sock"
    swarmMode: false
    useBindPortIP: false
    network: "traefik"
  file:
    watch: true
    directory: "/etc/traefik/config"
    debugLogGeneratedTemplate: true

entryPoints:
  http:
    address: ":52080"
    forwardedHeaders:
      insecure: true
  https:
    address: ":52443"
    forwardedHeaders:
      insecure: true
  ssh:
    address: ":52022"
    forwardedHeaders:
      insecure: true

certificatesResolvers:
  my:
    acme:
      email: "CLOUDFLARE邮箱"
      storage: "/data/ssl/acme.json"
      dnsChallenge:
        resolvers: ["1.1.1.1:53", "8.8.8.8:53"]
        provider: "cloudflare"
        delayBeforeCheck: 30
metrics:
  prometheus:
    buckets:
      - 0.1
      - 0.3
      - 1.2
      - 5.0

值得注意的是,因为运营商屏蔽了2244380端口,于是我使用520225244352080做映射替代,如未被屏蔽,请忽略。

为了自动申请SSL证书,提交成功率,我才用DNS Challenge的方式校验有效性,因此需Cloudflare的环境信息,如果你的域名没有配置Cloudflare解析,可以根据这篇文章置换相应变量。

随后,进入config目录。

创建dashboard.nas.yfgeek.com.toml文件,作为traefik展示面板的配置文件,因为相对固化,所以采用文件配置文件的形式,traefik支持文件加载配置。

[http.middlewares.dash-compress.compress]
[http.middlewares.dash-auth.basicAuth]
  users = [
    "test:$apr1$ux2tmr06$Qz5r/BNEfzdxriR/0o30Z1",
  ]

[http.routers.dashboard]
  rule = "Host(`dashboard.nas.yfgeek.com`)"
  entrypoints = ["http"]
  service = "dashboard@internal"
  middlewares = ["dash-auth", "dash-compress"]

[http.routers.api]
  rule = "Host(`dashboard.nas.yfgeek.com`) && PathPrefix(`/api`)"
  entrypoints = ["http"]
  service = "api@internal"
  middlewares = ["dash-auth", "dash-compress"]

[http.routers.ping]
  rule = "Host(`dashboard.nas.yfgeek.com`) && PathPrefix(`/ping`)"
  entrypoints = ["http"]
  service = "ping@internal"
  middlewares = ["dash-auth", "dash-compress"]

这个文件中,我们设置了一个用于验证的中间件,进入网站之前会默认进行验证,密码是htpasswd生成规则,例子中用户名是test,密码是test,如需定制,可到这个网站生成密码

全部创建好后,目录结构如下:

|____config
| |____dashboard.nas.yfgeek.com.toml
|____ssl
|____docker-compose.yml
|____traefik.yml

确认无误,我们使用启动大法,执行如下命令。

docker-compose up -d
docker container logs traefik -f

不出意外,服务即将启动成功,可以看到日志,如果有问题就见招拆招即可。

具体可参考:https://github.com/yfgeek/traefik-docker-compose/tree/master/traefik

搭建监控系统

监控系统,你可能跟我说ELK?别试了,我已经试过了,这个对内存要求太高了,群晖咱承受不起,最终采用的方案如下:

Grafana

Grafana 是一个用于监控和可视化观测的开源平台,支持非常丰富的数据源,在 Loki 技术栈中它专门用来展示来自 Prometheus 和 Loki 等数据源的时间序列数据。此外,还允许我们进行查询、可视化、报警等操作,可以用于创建、探索和共享数据 Dashboard,鼓励数据驱动的文化。

Prometheus

Prometheus受启发于Google的Brogmon监控系统(相似的Kubernetes是从Google的Brog系统演变而来),是一个开放性的监控解决方案,用户可以非常方便的安装和使用Prometheus并且能够非常方便的对其进行扩展。基于全新存储层的2.0版本,能更好地与容器平台、云平台配合。

Promtail

Promtail 是用来将容器日志发送到 Loki 或者 Grafana 服务上的日志收集工具,该工具主要包括发现采集目标以及给日志流添加上 Label 标签,然后发送给 Loki,另外 Promtail 的服务发现是基于 Prometheus 的服务发现机制实现的。

Loki

Loki 是一个受 Prometheus 启发的可以水平扩展、高可用以及支持多租户的日志聚合系统,使用了和 Prometheus 相同的服务发现机制,将标签添加到日志流中而不是构建全文索引。正因为如此,从 Promtail 接收到的日志和应用的 metrics 指标就具有相同的标签集。所以,它不仅提供了更好的日志和指标之间的上下文切换,还避免了对日志进行全文索引。

开搞

cd /volume1/docker/
mkdir monitoring

拷贝如下目录的全部文件:https://github.com/yfgeek/traefik-docker-compose/tree/master/monitoring

编辑docker-compose.yml文件,更改granafa的host地址,可更改为内网。

version: '3.7'

services:
  prometheus:
    image: prom/prometheus
    volumes:
      - ./prometheus/:/etc/prometheus/
      - prometheus_data:/prometheus
    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'
    networks:
      - inbound
    labels:
       - "traefik.enable=true"
       - "traefik.http.routers.prometheus.rule=Host(`prometheus`)"
       - "traefik.http.routers.prometheus.entrypoints=http"
       - "traefik.http.routers.prometheus.service=prometheus"
       - "traefik.http.services.prometheus.loadbalancer.server.port=9090"
       - "traefik.docker.network=inbound"
  
  grafana:
    image: grafana/grafana
    depends_on:
      - prometheus
    volumes:
      - grafana_data:/var/lib/grafana
      - ./grafana/provisioning/:/etc/grafana/provisioning/
    env_file:
      - ./grafana/config.monitoring
    networks:
      - inbound
    user: "472"
    labels:
        - "traefik.enable=true"
        - "traefik.http.routers.grafana.rule=Host(`grf.nas.yfgeek.com`,`grafana`)"
        - "traefik.http.routers.grafana.entrypoints=http"
        - "traefik.http.routers.grafana.service=grafana"
        - "traefik.http.services.grafana.loadbalancer.server.port=3000"
        - "traefik.docker.network=inbound"

  loki:
    image: grafana/loki
    expose:
      - "3100"
    volumes:
      - /volume1/docker/prometheus/loki/local-config.yaml:/etc/loki/local-config.yaml
      - loki_data:/loki
    command: -config.file=/etc/loki/local-config.yaml
    networks:
      - inbound

  promtail:
    image: grafana/promtail
    depends_on:
      - loki
    volumes:
      - /volume1/docker/traefik/logs:/var/log
      - /volume1/docker/prometheus/promtail/config.yml:/etc/promtail/config.yml
    command: -config.file=/etc/promtail/config.yml
    networks:
      - inbound


networks:
  inbound:
    name: inbound

volumes:
    prometheus_data: {}
    grafana_data: {}
    loki_data: {}

确认无误后,执行大法。

docker-compose up -d

等待docker都拉取完毕,创建好容器后,我们便可以通过访问设置的host地址,进入granafa登陆界面。

输入用户名admin 密码admin (密码后续可改),进入监控页面,点击如图所示的按钮,随后点击Add data source,添加数据源。

依次添加prometheus、loki

具体配置如下

prometheus地址:http://prometheus:9090

loki地址:http://loki:3100

设置完成后,点击Save & Test 看到绿色成功,即设置成功。

日志检索

数据源添加完毕后,可以到Explore页面中,检查日志是否上送。

Traefik 大盘

点击加号按钮,点击Import,通过如下ID导入 12250,随后Import即可。

Loki 大盘

因为我在Promtail过程中更改了默认的job名字,可根据ID 13713导入后,手动更改配置,也可以直接通过JSON导入。点击加号按钮,点击Import,通过如下JSON导入:

{"annotations":{"list":[{"builtIn":1,"datasource":"-- Grafana --","enable":true,"hide":true,"iconColor":"rgba(0, 211, 255, 1)","name":"Annotations & Alerts","type":"dashboard"}]},"description":"Loki version 2 showcase using JSON Traefik access logs.","editable":true,"gnetId":13713,"graphTooltip":0,"id":4,"links":[],"panels":[{"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"thresholds":{"mode":"absolute","steps":[]}},"overrides":[]},"gridPos":{"h":2,"w":24,"x":0,"y":0},"id":32,"interval":"","options":{"content":"<div class=\"left dashboard-header\">\n   <img src=\"https://marketplace-assets.digitalocean.com/logos/loki-logo.svg\" style=\"height:29px;\"/>\n  <span>Traefik Dashboard</span>\n</div>","mode":"html"},"pluginVersion":"7.4.3","targets":[{"expr":"loki_build_info","format":"table","instant":false,"interval":"","legendFormat":"","refId":"A"}],"timeFrom":null,"timeShift":null,"title":"","transparent":true,"type":"text"},{"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"purple","value":null}]},"unit":"short"},"overrides":[]},"gridPos":{"h":4,"w":6,"x":0,"y":2},"id":4,"interval":"1m","options":{"colorMode":"background","graphMode":"area","justifyMode":"auto","orientation":"auto","reduceOptions":{"calcs":["sum"],"fields":"","values":false},"text":{},"textMode":"value"},"pluginVersion":"7.4.3","targets":[{"expr":"sum(count_over_time({filename=\"/var/log/access.log\"} |= \"RequestProtocol\" [$__interval]))","legendFormat":"","refId":"A"}],"timeFrom":"1h","timeShift":null,"title":"Total requests  ","transformations":[],"transparent":true,"type":"stat"},{"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"light-blue","value":null}]},"unit":"short"},"overrides":[]},"gridPos":{"h":8,"w":9,"x":6,"y":2},"id":5,"interval":"30s","options":{"colorMode":"background","graphMode":"area","justifyMode":"auto","orientation":"auto","reduceOptions":{"calcs":["sum"],"fields":"","values":false},"text":{},"textMode":"auto"},"pluginVersion":"7.4.3","targets":[{"expr":"sum by (OriginStatus) (count_over_time({filename=\"/var/log/access.log\"} |= \"RequestProtocol\" | json |  __error__=\"\" [$__interval]))","legendFormat":"HTTP Status: {{OriginStatus}}","refId":"A"}],"timeFrom":"3h","timeShift":null,"title":"Requests per status code","transformations":[],"transparent":true,"type":"stat"},{"cacheTimeout":null,"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"mappings":[],"noValue":"0","thresholds":{"mode":"absolute","steps":[{"color":"purple","value":null},{"color":"red","value":80}]},"unit":"percent"},"overrides":[]},"gridPos":{"h":4,"w":4,"x":15,"y":2},"id":19,"interval":"5m","links":[],"maxDataPoints":1,"options":{"colorMode":"background","graphMode":"none","justifyMode":"center","orientation":"auto","reduceOptions":{"calcs":["mean"],"fields":"","values":false},"text":{},"textMode":"value"},"pluginVersion":"7.4.3","targets":[{"expr":" sum(rate({filename=\"/var/log/access.log\"} |~ \"RequestProtocol\" | json | OriginStatus >= 400 |__error__=\"\"[$__interval])) / (sum(rate({job=\"/var/log/traefik.log\"} |~ \"RequestProtocol\" | json | __error__=\"\"[$__interval])) / 100)","legendFormat":"","refId":"A"}],"timeFrom":"1h","timeShift":null,"title":"% of  4/5xx ","transparent":true,"type":"stat"},{"aliasColors":{},"bars":false,"cacheTimeout":null,"dashLength":10,"dashes":false,"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"thresholds":{"mode":"absolute","steps":[]},"unit":"none"},"overrides":[]},"fill":1,"fillGradient":0,"gridPos":{"h":4,"w":5,"x":19,"y":2},"hiddenSeries":false,"id":36,"interval":"1m","legend":{"avg":false,"current":false,"hideEmpty":true,"hideZero":true,"max":false,"min":false,"show":false,"total":false,"values":false},"lines":true,"linewidth":1,"links":[],"nullPointMode":"null","options":{"alertThreshold":true},"percentage":false,"pluginVersion":"7.4.3","pointradius":2,"points":false,"renderer":"flot","seriesOverrides":[],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"expr":" sum by (OriginStatus,ServiceName) (count_over_time({filename=\"/var/log/access.log\"} |~ \"RequestProtocol\" | json | OriginStatus >= 400 |__error__=\"\"[$__interval]))","legendFormat":" {{ServiceName}} / {{OriginStatus}} ","refId":"A"}],"thresholds":[],"timeFrom":"3h","timeRegions":[],"timeShift":null,"title":" 4/5xx  Services","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"transparent":true,"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":false,"values":[]},"yaxes":[{"$$hashKey":"object:405","decimals":0,"format":"none","label":null,"logBase":1,"max":null,"min":"0","show":true},{"$$hashKey":"object:406","format":"short","label":null,"logBase":1,"max":null,"min":null,"show":false}],"yaxis":{"align":false,"alignLevel":null}},{"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"purple","value":null}]}},"overrides":[]},"gridPos":{"h":4,"w":6,"x":0,"y":6},"id":22,"interval":"5m","options":{"colorMode":"background","graphMode":"none","justifyMode":"auto","orientation":"auto","reduceOptions":{"calcs":["mean"],"fields":"","values":false},"text":{},"textMode":"value"},"pluginVersion":"7.4.3","targets":[{"expr":"count(sum by (ClientHost) (count_over_time({filename=\"/var/log/access.log\"}|= \"RequestProtocol\" | json |  __error__=\"\" [$__interval])))","legendFormat":"","refId":"A"}],"timeFrom":"5m","timeShift":null,"title":"Users right now","transformations":[],"transparent":true,"type":"stat"},{"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"purple","value":null}]},"unit":"decbytes"},"overrides":[]},"gridPos":{"h":4,"w":8,"x":15,"y":6},"id":8,"interval":"1m","options":{"colorMode":"background","graphMode":"none","justifyMode":"center","orientation":"auto","reduceOptions":{"calcs":["sum"],"fields":"","values":false},"text":{},"textMode":"value"},"pluginVersion":"7.4.3","targets":[{"expr":"sum_over_time({filename=\"/var/log/access.log\"}|= \"RequestProtocol\" | json | OriginStatus=200 | unwrap DownstreamContentSize |  __error__=\"\" [$__interval])","legendFormat":"Bytes sent","refId":"A"}],"timeFrom":"5m","timeShift":null,"title":"Total Bytes Sent","transformations":[{"id":"reduce","options":{"reducers":["sum"]}},{"id":"organize","options":{"excludeByName":{},"indexByName":{},"renameByName":{"Total":"Bytes Sent"}}}],"transparent":true,"type":"stat"},{"aliasColors":{},"breakPoint":"50%","cacheTimeout":null,"combine":{"label":"Others","threshold":0},"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"thresholds":{"mode":"absolute","steps":[]}},"overrides":[]},"fontSize":"80%","format":"short","gridPos":{"h":8,"w":8,"x":0,"y":10},"id":33,"interval":"5m","legend":{"percentage":true,"show":true,"values":true},"legendType":"Right side","links":[],"maxDataPoints":3,"nullPointMode":"connected","pieType":"pie","pluginVersion":"7.3.4","strokeWidth":1,"targets":[{"expr":"sum by (RouterName) (count_over_time({filename=\"/var/log/access.log\"}|= \"RequestProtocol\" | json |  __error__=\"\" [$__interval]))","legendFormat":"{{RouterName}}","refId":"A"}],"timeFrom":"1h","timeShift":null,"title":"Requests Route","transformations":[],"transparent":true,"type":"grafana-piechart-panel","valueName":"current"},{"datasource":"Loki","fieldConfig":{"defaults":{"custom":{}},"overrides":[]},"gridPos":{"h":8,"w":16,"x":8,"y":10},"id":11,"interval":"","options":{"showLabels":false,"showTime":true,"sortOrder":"Descending","wrapLogMessage":false},"targets":[{"expr":"{filename=\"/var/log/access.log\"} |= \"RequestProtocol\"| json  | line_format \"Status:{{.OriginStatus}} Client From {{.ClientAddr}} {{.RequestMethod}} {{.RequestAddr}}{{.RequestPath}} Route To {{.ServiceAddr}}\"","legendFormat":"","refId":"A"}],"timeFrom":"5m","timeShift":null,"title":"Logs","transparent":true,"type":"logs"},{"aliasColors":{"95th percentile":"blue","max latency":"super-light-blue"},"bars":false,"dashLength":10,"dashes":false,"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"unit":"ns"},"overrides":[]},"fill":5,"fillGradient":9,"gridPos":{"h":9,"w":8,"x":0,"y":18},"hiddenSeries":false,"id":16,"interval":"30s","legend":{"alignAsTable":false,"avg":false,"current":false,"max":true,"min":false,"rightSide":false,"show":true,"total":false,"values":true},"lines":true,"linewidth":1,"nullPointMode":"null","options":{"alertThreshold":true},"percentage":false,"pluginVersion":"7.4.3","pointradius":2,"points":false,"renderer":"flot","seriesOverrides":[{"$$hashKey":"object:232","alias":"max latency","dashes":true,"fillGradient":3}],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"expr":"quantile_over_time(0.95,{filename=\"/var/log/access.log\"} |= \"RequestProtocol\"| json | unwrap Duration |  __error__=\"\"  [$__interval]) by (ServiceName)","hide":false,"legendFormat":" {{ ServiceName }}","refId":"C"}],"thresholds":[{"$$hashKey":"object:168","colorMode":"critical","fill":true,"line":true,"op":"gt","value":0.3,"yaxis":"left"}],"timeFrom":null,"timeRegions":[],"timeShift":null,"title":"95th percentile of Request Time","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"transparent":true,"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":true,"values":[]},"yaxes":[{"$$hashKey":"object:178","format":"ns","label":null,"logBase":1,"max":null,"min":null,"show":true},{"$$hashKey":"object:179","format":"short","label":null,"logBase":1,"max":null,"min":null,"show":false}],"yaxis":{"align":false,"alignLevel":null}},{"aliasColors":{"95th percentile":"blue","max latency":"super-light-blue"},"bars":false,"dashLength":10,"dashes":false,"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"unit":"ns"},"overrides":[]},"fill":5,"fillGradient":9,"gridPos":{"h":9,"w":8,"x":8,"y":18},"hiddenSeries":false,"id":34,"interval":"30s","legend":{"alignAsTable":false,"avg":false,"current":false,"max":false,"min":false,"rightSide":false,"show":true,"total":false,"values":false},"lines":true,"linewidth":1,"nullPointMode":"null","options":{"alertThreshold":true},"percentage":false,"pluginVersion":"7.4.3","pointradius":2,"points":false,"renderer":"flot","seriesOverrides":[{"$$hashKey":"object:232","alias":"max latency","dashes":true,"fillGradient":3}],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"expr":"max by (ServiceName) (max_over_time({filename=\"/var/log/access.log\"} |= \"RequestProtocol\" |json | unwrap Duration |  __error__=\"\"  [$__interval]))","hide":false,"legendFormat":"{{ ServiceName}}","refId":"D"}],"thresholds":[{"$$hashKey":"object:168","colorMode":"critical","fill":true,"line":true,"op":"gt","value":0.3,"yaxis":"left"}],"timeFrom":null,"timeRegions":[],"timeShift":null,"title":"Max Age of Request Time","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"transparent":true,"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":true,"values":[]},"yaxes":[{"$$hashKey":"object:178","format":"ns","label":null,"logBase":1,"max":null,"min":null,"show":true},{"$$hashKey":"object:179","format":"short","label":null,"logBase":1,"max":null,"min":null,"show":false}],"yaxis":{"align":false,"alignLevel":null}},{"aliasColors":{"95th percentile":"blue","max latency":"super-light-blue"},"bars":false,"dashLength":10,"dashes":false,"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"unit":"decbytes"},"overrides":[]},"fill":5,"fillGradient":9,"gridPos":{"h":9,"w":8,"x":16,"y":18},"hiddenSeries":false,"id":35,"interval":"30s","legend":{"alignAsTable":false,"avg":false,"current":false,"max":false,"min":false,"rightSide":false,"show":true,"total":false,"values":false},"lines":true,"linewidth":1,"nullPointMode":"null","options":{"alertThreshold":true},"percentage":false,"pluginVersion":"7.4.3","pointradius":2,"points":false,"renderer":"flot","seriesOverrides":[{"$$hashKey":"object:232","alias":"max latency","dashes":true,"fillGradient":3}],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"expr":"sum by (ServiceName) (sum_over_time({filename=\"/var/log/access.log\"} |= \"RequestProtocol\" |json | unwrap RequestContentSize |  __error__=\"\"  [$__interval]))","hide":false,"legendFormat":"{{ ServiceName}}","refId":"D"}],"thresholds":[{"$$hashKey":"object:168","colorMode":"critical","fill":true,"line":true,"op":"gt","value":0.3,"yaxis":"left"}],"timeFrom":null,"timeRegions":[],"timeShift":null,"title":"Requests Size","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"transparent":true,"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":true,"values":[]},"yaxes":[{"$$hashKey":"object:178","format":"decbytes","label":null,"logBase":1,"max":null,"min":null,"show":true},{"$$hashKey":"object:179","format":"short","label":null,"logBase":1,"max":null,"min":null,"show":false}],"yaxis":{"align":false,"alignLevel":null}}],"refresh":false,"schemaVersion":27,"style":"dark","tags":[],"templating":{"list":[]},"time":{"from":"now-1h","to":"now"},"timepicker":{"refresh_intervals":["10s","30s","1m","5m","15m","30m","1h","2h","1d"]},"timezone":"","title":"Traefik Via Loki","uid":"fJarCeaGk","version":2}

到这里,两个大盘就完美展示了,具体Grafana如何使用可自行查阅资料。

值得注意的是,后续增加容器服务,只要注册在Traefik,就会自动联动到监控系统,无需任何二次配置,实现简单,便捷,统一管理。

本文所涉及的文件均在此处可找到:https://github.com/yfgeek/traefik-docker-compose

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,271评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,275评论 2 380
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,151评论 0 336
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,550评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,553评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,559评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,924评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,580评论 0 257
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,826评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,578评论 2 320
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,661评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,363评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,940评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,926评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,156评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,872评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,391评论 2 342

推荐阅读更多精彩内容