Guidelines

This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes
717 views
717 views

I want to add a "hostname" label to my metrics in Prometheus, because I don't need domain or port information in my dashboards.

I tried adding this to the respective exporter settings in my Prometheus config:

relabel_configs:
- source_labels:
  - instance
  regex: "([a-z][a-z0-9-]*)(\\.[a-z][a-z0-9-]*)*(:[0-9]+)?"
  target_label: hostname

but it doesn't seem to have an effect. Even if I remove the regular expression, I don't get a label "hostname" in the scraped metrics when I would have expected a copy of the label "instance."

in Sysadmin
by (125)
3 20 38
edit history

Please log in or register to answer this question.

1 Answer

0 votes
 

The label instance seems to be generated at a later point in time. For generating an additional hostname label use the special label __address__ instead:

relabel_configs:
- source_labels:
  - __address__
  regex: "([a-z][a-z0-9-]*)(\\.[a-z][a-z0-9-]*)*(:[0-9]+)?"
  target_label: hostname
by (125)
3 20 38
edit history
...