title: Relabel instance to hostname in Prometheus
body: <p>I have Prometheus scraping metrics from node exporters on several machines with a config like this:</p>
  
  <pre><code>scrape_configs:
    - job_name: node_exporter
      static_configs:
        - targets:
          - 1.2.3.4:9100
          - 2.3.4.5:9100
          - 3.4.5.6:9100
  </code></pre>
  
  <p>When viewed in Grafana, these instances are assigned rather meaningless IP addresses; instead, I would prefer to see their hostnames. I think you should be able to relabel the <code>instance</code> label to match the hostname of a node, so I tried using relabelling rules like this, to no effect whatsoever:</p>
  
  <pre><code>relabel_configs:
    - source_labels: ['nodename']
      target_label: 'instance'
  </code></pre>
  
  <p>I can manually relabel every target, but that requires hardcoding every hostname into Prometheus, which is not really nice. I see that the node exporter provides the metric <code>node_uname_info</code> that contains the hostname, but how do I extract it from there?</p>
  
  <pre><code>node_uname_info{domainname="(none)",machine="x86_64",nodename="myhostname",release="4.13.0-32-generic",sysname="Linux",version="..."} 1
  </code></pre>