'prometheus how to change instance name

"targets": [ "10.123.175.30:9100","10.125.150.14:9100"], "labels": { "env": "dev", "job": "node", "group": "developer" }

for those targets, can I map those IP addresses to instanace name ? such as "host1:9100", "host2:9100" (grafana will have better display then.)

or modify /etc/hosts is best approach?



Solution 1:[1]

You need to feed in the host name to Prometheus in the first place, rather than an IP address. Prometheus will resolve it when scraping.

Solution 2:[2]

instance label can be overridden via labels section inside static_config:

- scrape_configs:
  - job_name: node_exporter
    static_configs:
    - targets: ["10.123.175.30:9100"]
      labels:
        instance: host-foo
    - targets: ["10.125.150.14:9100"]
      labels:
        instance: host-bar

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 brian-brazil
Solution 2 valyala