I’m trying to build an alert that detects when one Traefik node has lost part of its dynamic configuration (Consul Catalog provider), i.e. a router that exists on the other nodes is missing on that node.
Setup
6 Traefik instances (v2.x) behind a load balancer, routers and services discovered via Consul Catalog
Prometheus metrics enabled with addEntryPointsLabels, addServicesLabels and addRoutersLabels
Grafana alerting on top of Prometheus
What I’ve tried
Reload metrics (traefik_config_reloads_total, last reload age): they only tell me a reload happened, not what config ended up loaded.
404 without route ratio: Traefik-generated 404s (entrypoint 404s minus service 404s) divided by total requests:
clamp_min(
sum by (instance) (rate(traefik_entrypoint_requests_total{code="404"}[5m]))
- (sum by (instance) (rate(traefik_service_requests_total{code="404"}[5m]))
or sum by (instance) (rate(traefik_entrypoint_requests_total{code="404"}[5m])) * 0),
0)
/ sum by (instance) (rate(traefik_entrypoint_requests_total[5m]))
It works as a symptom, but it’s noisy (about 33 episodes above 1% in 7 days, mostly scanners or invalid hosts), and it doesn’t tell me which router is missing.
Comparing routers across nodes using traefik_router_requests_total:
## scalar(count(up{job=“traefik”} == 1))
count by (router) (count by (router, instance) (traefik_router_requests_total{router=~".+@consulcatalog"})) > 0
This returned one router present on only 4 of 6 nodes. However, its request rate is 0 on those 4 nodes, so I can’t tell whether the router is really missing on the other 2 or if those nodes simply never received traffic for it.
The core problem
traefik_router_requests_total only exists after a router receives its first request, so a missing router is indistinguishable from an unused one. As far as I can tell, Traefik doesn’t expose a gauge such as “routers loaded” or “routers by provider/status”.
Questions
Is there a Prometheus metric in Traefik that reflects the number of routers (or services) currently loaded per instance, independent of traffic?
If not, what is the recommended approach to monitor this? Options I’m considering:
json_exporter (or similar) scraping /api/http/routers on each node and comparing counts
A scheduled script or workflow that compares /api/http/routers across nodes
Comparing against Consul’s registered services with Traefik tags
Does anyone already run an alert for “node X is missing routers compared to its peers”? How did you avoid false positives after restarts or deployments?
As far as I know, Traefik has no “routers loaded” gauge, and traefik_router_* series only exist after a router gets traffic. The workaround is to read the router list from Traefik’s API, which reflects the loaded config regardless of traffic.
Export one series per router, per node (json_exporter)
count by (router) (traefik_router_loaded_present)
< scalar(count(count by (instance) (traefik_router_loaded_present)))
Each result is a router that isn’t loaded on every reporting node, so this assumes all routers are expected on all nodes. Use a pending period of 5m or more to avoid firing during restarts and deploys.
Thank you very much for taking the time to analyze this and share your proposal. I find the approach of querying the Traefik API directly—to detect loaded routers regardless of whether they are receiving traffic—very useful; it allows for more reliable alerts. Thanks for the explanation and for sharing the example queries and configurations.
I think comparing the router lists through the API is probably the more reliable direction here.
The request metrics seem a bit misleading for this particular problem. A router with no traffic and a router that doesn’t exist can look pretty much the same.
One thing I’d be careful about though is alerting on every difference between nodes. During a deployment or a Consul update, I’d expect them to be briefly out of sync.
Maybe only alert if the same router is missing from a particular node for a few consecutive checks?
I’m not entirely sure what the best reference would be either. Comparing against Consul’s expected configuration might be safer than assuming the majority of Traefik nodes are always correct.
set the alert rule’s pending period to 5m or more. Each result is its own alert instance with its own timer, so a router that is only briefly missing during a deploy won’t fire.
use a fixed list of expected routers. It doesn’t depend on the other nodes being correct, and it catches a router missing on every node:
Each result is an expected router missing on a specific node. Alert when the value is above 0, and set “Alert state if no data” to Normal, since a healthy state returns nothing.
Add one or label_replace(...) line per router, using the exact router label value including @consulcatalog.
Keep a separate alert on up{job="traefik_routers"} == 0 for down nodes.