hello, i'm trying to analyze treafik metrics in a docker swarm with prometheus but i can't find backend metrics such as traefik_backend_requests_total but traefik_config*, traefik_entrypoint* and traefik_service* metrics are there, how can i enable backend metrics?
i use traefik v2.2 but also with v2.0 is the same, the prometheus image is prom/prometheus:v2.17.2
please help me, thanks
hmm. Can you give us your configuration?
1 Like
traefik:
image: traefik:v2.2
command:
- "--api=true"
#- "--api.insecure=true"
- "--api.dashboard=true"
- "--providers.docker=true"
- "--providers.docker.watch=true"
- "--providers.docker.endpoint=unix:///var/run/docker.sock"
- "--providers.docker.swarmMode=true"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.network=frontend"
- "--providers.file.directory=/etc/traefik/dynamic_conf"
- "--entryPoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--metrics.prometheus=true"
- "--metrics.prometheus.buckets=0.1,0.3,1.2,5.0"
networks:
- frontend
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik/certs:/tools/certs
- ./traefik/config.yml:/etc/traefik/dynamic_conf/config.yml:ro
ports:
- "80:80"
- "443:443"
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
- "traefik.http.routers.api_secure.entrypoints=websecure"
- "traefik.http.routers.api_secure.rule=(PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
- "traefik.http.routers.api_secure.tls=true"
- "traefik.http.routers.api_secure.service=api@internal"
- "traefik.http.routers.api_secure.middlewares=auth"
# echo $(htpasswd -nb admin admin) | sed -e s/\\$/\\$\\$/g
- "traefik.http.middlewares.auth.basicauth.users=admin:$$apr1$$WM/HkA9O$$LW0cXtHaPKlJxSbagnsbT/"
# redirects all traffic to https
- "traefik.http.routers.api.entrypoints=web"
- "traefik.http.routers.api.rule=(PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
- "traefik.http.routers.api.middlewares=redirect-to-https"
# Dummy service for Swarm port detection
- "traefik.http.services.dummy-svc.loadbalancer.server.port=9999"
restart_policy:
condition: on-failure
placement:
constraints:
- node.role == manager
.
.
.
prometheus:
image: prom/prometheus:v2.17.2
volumes:
- ./prometheus/:/etc/prometheus/
- ./prometheus/alert.rules:/etc/prometheus/alert.rules
- 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'
- '--web.external-url=http://localhost:80/prometheus/'
- '--web.route-prefix=/'
networks:
- frontend
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.prometheus.entrypoints=web"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
- "traefik.http.routers.prometheus_secure.entrypoints=websecure"
- "traefik.http.routers.prometheus_secure.rule=PathPrefix(`/prometheus`)"
- "traefik.http.middlewares.prometheus-stripprefix.stripprefix.prefixes=/prometheus"
- "traefik.http.routers.prometheus_secure.middlewares=prometheus-stripprefix,auth"
- "traefik.http.middlewares.auth.basicauth.users=admin:$$apr1$$WM/HkA9O$$LW0cXtHaPKlJxSbagnsbT/"
- "traefik.http.routers.prometheus_secure.tls=true"
- "traefik.http.services.prometheus.loadbalancer.server.port=9090"
- "traefik.http.routers.prometheus_secure.service=prometheus"
- "traefik.http.routers.prometheus.rule=PathPrefix(`/prometheus`)"
- "traefik.http.routers.prometheus.middlewares=redirect-to-https"
- "traefik.docker.network=frontend"
placement:
constraints:
- node.role==manager
restart_policy:
condition: on-failure
prometheus.yml:
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
evaluation_interval: 15s # By default, scrape targets every 15 seconds.
external_labels:
monitor: 'my-project'
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'traefik'
scrape_interval: 5s
dns_sd_configs:
- names:
- 'tasks.traefik'
type: 'A'
port: 8080
- job_name: 'cadvisor'
scrape_interval: 5s
dns_sd_configs:
- names:
- 'tasks.cadvisor'
type: 'A'
port: 8080
the broblem was born when i try to use a grafana dashbord that use traefik_backend_requests_total, but searcing on varius metrics i find traefik_service_requests_total, i think may be the same metrics, do you think there is some difference between backend and service?
No, it should be fine. Its just from different versions of Traefik. v1 versus v2
1 Like
oh ok, so just different name but is the same thing, thank you man