When Traefik is up and running and your routers/services are configured, it is important to monitor them. To do it, I'm going to set up Traefik to be scraped by Prometheus, among other things.
Version | Date | Comment |
---|---|---|
1 | 05/2022 | Post creation |
Goal : Configure Traefik and Prometheus
Environment : Debian 11.7
, Docker 23.x
, docker compose (plugin) 2.17.x
, Traefik 2.x
Execution context :
jho@vmi866042:/srv/docker/dc$ tree
.
├── conf
│ ├── acme.json
│ ├── traefik.yml
│ ├── traefikdynamic
│ │ ├── general.yml
│ │ ├── routersservices.yml
├── docker-compose.yml
└── logs
├── traefikAccess.log
├── traefik.log
This post is inspired by the official documentation. Traefik supports 4 monitoring backends : Datadog, MetricD, Prometheus et InfluxDB.
Metrics give you some information in real-time, like stats about configuration reloading, number of entry requests in HTTP or HTTPS, number of redirections, number of open connections...
Traefik configuration
I will use Prometheus to scrape Traefik metrics and store them locally. To do it, the main configuration file traefik.yml
needs to be updated with few options. In the entry points block, insert these lines : (port number can be changed)
entryPoints:
metrics:
address: ":9090"
At the end of the file, add this bloc (YAML format) :
metrics:
prometheus:
entryPoint: metrics
addEntryPointsLabels: true
addServicesLabels: true
addRoutersLabels: true
buckets:
- 0.1
- 0.3
- 1.2
- 5.0
Don't forget to restart Traefik to take into account. Beware of, do not expose this entry point to the web!
Prometheus configuration
Simply, add this bloc in the prometheus.yml
file:
...
scrape_configs:
- job_name: 'traefik'
static_configs:
- targets: ['traefik:9090']
Don't forget to change the port number if you changed it before in the traefik.yml
file. Now, Prometheus can scrape Traefik by the specific metrics entry point.
Every Traefik metrics in Prometheus are entitled traefik_
.
To-do : some PromQL rules/requests...