Answers: <p>You just have to use the hostname on your docker compose file like this:</p>
  
  <pre><code>hostname: whatever-{{.Node.Hostname}}
  </code></pre>
  
  <p>Note that you have to prepend something to the hostname to avoid hostnames duplicates. </p>
  
Answers: CC BY-SA 4.0
Answers: 2023-05-13T22:49:11.177Z
Answers: this doesn't seem to work. im not able to find that 'hostname' tag in grafana
Answers: mike01010
Answers: CC BY-SA 4.0
Answers: 2019-10-04T21:46:21.603Z
Answers: 2019-10-05T16:02:51.783Z
Answers: 2019-10-05T16:02:51.783Z
Answers: gespert
Body: <p>I have setup my monitoring with the <em>cadvisor, node-exporter, prometheus, grafana</em> stack in my clustered environment using docker swarm.</p>
  
  <p>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?</p>
  
  <p>For my kubernetes environments this works ootb, because all metrics are extended by the <code>kubernetes_io_hostname</code>, that contains the actual hostname.</p>
  
  <p>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 <a href="https://github.com/bvis/docker-node-exporter" rel="nofollow noreferrer">https://github.com/bvis/docker-node-exporter</a>). 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.</p>
  
  <p>Is there an easy way to get the <code>hostname</code> of the node into my node-exporter metrics? Maybe by just mounting the hosts <code>/etc/hostname</code> file to a specific place in the node-exporter container, or something like that?</p>
  
Tags: <docker-swarm><prometheus>
Title: How to get hostname from node-exporter in Docker Swarm?
UserDisplayName: Max N.
ThreadText: # How to get hostname from node-exporter in Docker Swarm?
  
  (Asked by: username_0 on 2018-10-25)
  
  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 `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?
  
  **Tags:** docker-swarm, prometheus
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-10-04. Score: 3
  
  You just have to use the hostname on your docker compose file like this:
  
  ```
  hostname: whatever-{{.Node.Hostname}}
  
  ```
  
  Note that you have to prepend something to the hostname to avoid hostnames duplicates.
  
  > **Comments:**
  > **username_2**: this doesn't seem to work. im not able to find that 'hostname' tag in grafana  
  
  ---
  
  