-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hostname labels for promtail to docker_sd_configs #6062
Comments
Hi @patsevanton, we are using the service discovery from Prometheus: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#docker_sd_config It lists these labels
Unfortunately hostname is not part of it. |
- job_name: "docker"
docker_sd_configs:
- host: "unix:///var/run/docker.sock"
refresh_interval: "5s"
pipeline_stages:
- static_labels:
host: "{{ hostname }}" |
If you can set your hostname when creating
|
There is nothing like I tried it with:
but it didn't work. I got |
@durcon because your indentation is wrong + it is pipeline_stages:
- static_labels:
host: "{{ hostname }}" https://grafana.com/docs/loki/latest/clients/promtail/stages/static_labels/ |
I tried your solution first, but unfortunately the copied lines didn't work. Because I didn't find any documentation, I tried again with Now I use shane-axiom's solution, which works without any changes.
Thank you for the link. The documentation seems to be inconsistent, because the first link doesn't contain |
@shane-axiom
Your solution worked with version 2.5. Now with version 2.6.1 it doesn't work anymore. Do you know the reason? Update It is only a view problem, Promtail doesn't show the external_labels in the |
Here's my workaround in docker-compose.yml if anyone interested:
|
Try with this config. And it's works: config:
snippets:
addScrapeJobLabel: true
extraScrapeConfigs: |
- job_name: docker-container
pipeline_stages:
- docker: {}
docker_sd_configs:
- host: unix:///var/run/docker.sock
relabel_configs:
// other configs
- replacement: ${HOSTNAME}
target_label: node_name
extraArgs:
- -config.expand-env=true |
One solution is :
In promtail's configuration file, add
It works under CentOS 8 and Debian 11. |
I would recommend using it like this: promtail:
image: grafana/promtail
entrypoint: [ "/bin/sh","-c" ]
command:
- |
export DOCKER_HOST=$$(cat /run/secrets/DOCKER_HOST)
/usr/bin/promtail -config.file=/etc/promtail-config.yml -client.external-labels=hostname=$${DOCKER_HOST}
configs:
- source: promtail-yml
target: /etc/promtail-config.yml
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
deploy:
mode: global
secrets:
- DOCKER_HOST
secrets:
DOCKER_HOST:
file: /etc/hostname
|
@durcon thank you for updating that comment, i wasted a bit of time expecting to see it in the columns on promtail dashboard too >< Can confirm external_label still works |
Hello! Thanks for promtail and loki
I try adding hostname labels for promtail to docker_sd_configs.
promtail.yml:
Get error
The text was updated successfully, but these errors were encountered: