My question is an addition to Prometheus dns service discovery in docker swarm.
I define the prometheus scrape targets as follows:
- job_name: 'node-exporter'
dns_sd_configs:
- names:
- 'tasks.nodeexporter'
type: 'A'
port: 9100
This works fine but results in prometheus using the IP of the docker container as instance label.
I tried to relabel the instance label as follows:
relabel_configs:
- source_labels: [__meta_dns_name]
target_label: instance
But doing so results in all instances of node-exporter having the same label "tasks.nodeexporter".
Is it somehow possible to relabel the instance label to something like tasks.nodexporter_1, tasks.nodeexporter_2, ...?
Service discovery for docker swarm setups isn’t supported well in Prometheus as there are many features missing on the swarm side.
The dns service discovery is one way to mitigate those missing features but in my opinion it isn’t a good solution and I recommend to not use it in production:
Altogether these issues don’t allow this approach for being a reliable source for a monitoring system.
If you are really tied to using docker swarm, you should consider building a more sustainable solution by querying the docker api programmatically and using the file_sd service discovery mechanism of Prometheus. Please see this poc by containersolutions for reference: https://github.com/ContainerSolutions/prometheus-swarm-discovery