RousselTMLEARNING

Proxy & networking

Traefik: metrics with Prometheus and OpenTelemetry

Expose Traefik metrics (Prometheus or OTLP), understand the series per entrypoint, router and service, write useful PromQL queries and essential alerts.

1. Enabling metrics #

Prometheus or OTLP.

Configuration #

entryPoints:
  metrics:
    address: ":8082"
metrics:
  prometheus:
    entryPoint: metrics            # point d'exposition séparé du trafic public
    addRoutersLabels: true         # séries par routeur (attention à la cardinalité)
    addServicesLabels: true
    buckets: [0.05, 0.1, 0.3, 1.2, 5.0]
# ou : metrics.otlp.grpc.endpoint: otel-collector:4317

Collecting #

scrape_configs:
  - job_name: traefik
    static_configs: [{ targets: ['traefik:8082'] }]

2. Useful metrics and queries #

The RED method.

PromQL queries #

RED method
Rate, errors, duration: enough to detect most incidents.
# Débit par service
sum by (service) (rate(traefik_service_requests_total[5m]))
# Taux d'erreurs 5xx par service
sum by (service) (rate(traefik_service_requests_total{code=~"5.."}[5m]))
  / sum by (service) (rate(traefik_service_requests_total[5m]))
# Latence p95 par service
histogram_quantile(0.95, sum by (le, service) (rate(traefik_service_request_duration_seconds_bucket[5m])))
# Backends déclarés indisponibles par le health check
traefik_service_server_up == 0
# Jours avant expiration des certificats
(traefik_tls_certs_not_after - time()) / 86400

Metric families #

PrefixLevel
traefik_entrypoint_*Entrypoint (global traffic per port)
traefik_router_*Router (per routing rule)
traefik_service_*Service (per backend): the most useful
traefik_config_*, traefik_tls_certs_*Configuration reloads, certificates

3. Alerts #

Few, but useful.

Examples #

groups:
  - name: traefik
    rules:
      - alert: TraefikTauxErreurs5xx
        expr: |
          sum by (service) (rate(traefik_service_requests_total{code=~"5.."}[5m]))
            / sum by (service) (rate(traefik_service_requests_total[5m])) > 0.05
        for: 10m
        labels: { severity: page }
      - alert: TraefikCertificatBientotExpire
        expr: (traefik_tls_certs_not_after - time()) / 86400 < 14
        labels: { severity: ticket }
Good practice: Import the official Traefik Grafana dashboard as a starting point, then keep only the panels that serve your diagnoses.

Related articles

Traefik: securing and transforming requests with middlewares (BasicAuth, ForwardAuth…)

Traefik middlewares modify requests and responses between the router and the service: BasicAuth and ForwardAu…

Traefik: providers (Docker, Kubernetes, Nomad, Consul, files, key-value stores)

Providers feed Traefik's dynamic configuration: service discovery for Docker, Swarm, Kubernetes, Nomad and Co…

Traefik as an Ingress Controller for Kubernetes (Helm, IngressRoute, Gateway API)

Install Traefik in Kubernetes with Helm and publish applications with Ingress, the IngressRoute and Middlewar…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!