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.
Goal : Configure Traefik and Prometheus
docker compose (plugin) 2.17.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...
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!
Simply, add this bloc in the
... 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
To-do : some PromQL rules/requests...