snippetMinor
How to get hostname from node-exporter in Docker Swarm?
Viewed 0 times
swarmdockernodeexportergethostnamehowfrom
Problem
I have setup my monitoring with the cadvisor, node-exporter, prometheus, grafana stack in my clustered environment using docker swarm.
What is the easiest way to get my actual hostnames picked up by node-exporter, so I can configure my dashboards to filter by node names in grafana?
For my kubernetes environments this works ootb, because all metrics are extended by the
The only solution to this I found, so far, was to introduce my own metric, that creates the combination between node ids and node names (like done by https://github.com/bvis/docker-node-exporter). But I really like to use the vanilla image (for update reasons, for example) and also mounting some file with the configuration on all machines seems to be too much effort to do this.
Is there an easy way to get the
What is the easiest way to get my actual hostnames picked up by node-exporter, so I can configure my dashboards to filter by node names in grafana?
For my kubernetes environments this works ootb, because all metrics are extended by the
kubernetes_io_hostname, that contains the actual hostname.The only solution to this I found, so far, was to introduce my own metric, that creates the combination between node ids and node names (like done by https://github.com/bvis/docker-node-exporter). But I really like to use the vanilla image (for update reasons, for example) and also mounting some file with the configuration on all machines seems to be too much effort to do this.
Is there an easy way to get the
hostname of the node into my node-exporter metrics? Maybe by just mounting the hosts /etc/hostname file to a specific place in the node-exporter container, or something like that?Solution
You just have to use the hostname on your docker compose file like this:
Note that you have to prepend something to the hostname to avoid hostnames duplicates.
hostname: whatever-{{.Node.Hostname}}Note that you have to prepend something to the hostname to avoid hostnames duplicates.
Code Snippets
hostname: whatever-{{.Node.Hostname}}Context
StackExchange DevOps Q#5254, answer score: 3
Revisions (0)
No revisions yet.