How to alert when a Traefik node is missing routers (Consul Catalog provider)? Router metrics only exist with traffic

Hi all,

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

  1. Reload metrics (traefik_config_reloads_total, last reload age): they only tell me a reload happened, not what config ended up loaded.
  2. 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.

  1. 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

  1. Is there a Prometheus metric in Traefik that reflects the number of routers (or services) currently loaded per instance, independent of traffic?
  2. 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
  3. 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?

Thanks in advance!

Hi @davidacevedodev,

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)

modules:
  traefik_routers:
    metrics:
      - name: traefik_router_loaded
        type: object
        path: '{[*]}'
        labels:
          router: '{.name}'
        values:
          present: 1
- job_name: traefik_routers
  metrics_path: /probe
  params:
    module: [traefik_routers]
  static_configs:
    - targets:
        - http://traefik-1:8080/api/http/routers?per_page=1000
        # ... one per node
  relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: json-exporter:7979

Alert: router missing on at least one node

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.

Alert when a node reports no routers

up{job="traefik_routers"} unless on(instance) traefik_router_loaded_present

This catches a node whose API can’t be read or that returns an empty list, which the comparison above would silently skip.

Tested with json_exporter v0.7.0 and promtool test rules on sample data.

Thanks for fixing the formatting, @jangaraj! Much appreciated

Hi @infofcc3

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.

Hi @whitescreendev,

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:

(
  label_replace(up{job="traefik_routers"} == 1, "router", "web@consulcatalog", "", "")
  or label_replace(up{job="traefik_routers"} == 1, "router", "api@consulcatalog", "", "")
)
unless on(instance, router) traefik_router_loaded_present

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.

Hi @davidacevedodev just wanted to check if you got the solution . Happy to help further if you are facing any issues .