Traefik查询活动/死后端

时间:2019-03-05 09:00:28

标签: docker-swarm traefik

我们在docker swarm上安装了treafik,并通过traefik平衡了多项服务。每个服务至少有两个后端,其中包含wrr和运行状况检查。

是否有一种方法(api,其余端点,日志文件等等)来找出哪些前端具有死掉的后端?死了,我的意思是treafik通过健康检查在哪些后端上检测到它们不符合平衡条件?

最佳做法是什么?

1 个答案:

答案 0 :(得分:1)

我看到两种获取信息的方式:

Traefik日志

查看Traefik log,它提供了运行状况检查的跟踪信息:

time="2019-03-05T22:19:35Z" level=debug msg="Refreshing health check for backend: backend-web-so-55004614",
time="2019-03-05T22:19:35Z" level=warning msg="Health check still failing. Backend: \"backend-web-so-55004614\" URL: \"http://192.168.80.2:80\" Reason: received error status code: 404",
time="2019-03-05T22:19:36Z" level=debug msg="Refreshing health check for backend: backend-web-so-55004614",
time="2019-03-05T22:19:36Z" level=warning msg="Health check still failing. Backend: \"backend-web-so-55004614\" URL: \"http://192.168.80.2:80\" Reason: received error status code: 404",

Traefik /metrics

如果不方便解析Traefik日志,则可以激活Traefik Prometheus指标(默认情况下已启用):

docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p "80:80" -p "8080:8080" traefik --api --docker

然后,您可以在http://localhost:8080/metrics上进行HTTP查询,并查找包含_backend_server_up的行。这些行中的每行都告诉您您的后端正常运行。如果缺少后端,则表示后端不健康或已停止:

traefik_backend_server_up{backend="backend-robots",url="http://172.23.0.3:80"} 1
traefik_backend_server_up{backend="backend-smtp-ui",url="http://172.25.0.3:8025"} 1
traefik_backend_server_up{backend="backend-varnish-admin",url="http://172.23.0.8:6085"} 1
traefik_backend_server_up{backend="backend-varnish-http",url="http://172.23.0.8:6081"} 1
traefik_backend_server_up{backend="backend-web-apps",url="http://172.21.0.2:80"} 1
traefik_backend_server_up{backend="backend-web-report",url="http://172.19.0.6:80"} 1

您可以使用脚本查询此URL,也可以安装具有alerting rules

的Prometheus