Instance relabel from nodename?

3,270 views
Skip to first unread message

pand...@gmail.com

unread,
Feb 14, 2018, 11:33:35 PM2/14/18
to Prometheus Developers
I want to relabel 'instance' with the nodename label (hostname) from node-exporter.

Relevant config section below. I must be missing something simple...
(Also using Prom 2.0 & 15.x node-exporter)

relabel_configs:
- source_labels: [__meta_azure_machine_location]
target_label: location
- source_labels: [__meta_azure_machine_tag_Role]
target_label: role
- source_labels: [__meta_azure_machine_tag_Environment]
target_label: environment
- source_labels: [__meta_azure_machine_tag_Service]
target_label: service
- source_labels: [nodename]
target_label: instance

All other relabels work fine. Any advice is greatly appreciated.

Matthias Rampke

unread,
Feb 15, 2018, 3:28:20 AM2/15/18
to pand...@gmail.com, Prometheus Developers
To relabel a metric based on labels set by the metric source you need to use `metric_relabel_configs`, which are applied on the data after collection. Regular relabel configs are calculated before anything is scraped, because they can influence the scraping itself. Note that metric relabeling is a bit more expensive because it is applied to every single ingested data point.

You cannot relabel a metric based on a different metric at all, this is not supported and most likely never will be. It would open up huge complexity, both conceptually and computationally (how fo you label the first scrape? What if the source of that metric is down? Can you guarantee that the relabeling rules terminate?)

Additionally, relabelling the instance label has implications in target handling; you need to make sure it is always unique.

For this case, I would start by tagging all instances with their hostnames, and then you can use that (plus the port) as the instance label.

/MR

--
You received this message because you are subscribed to the Google Groups "Prometheus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-devel...@googlegroups.com.
To post to this group, send email to prometheus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-developers/307d8f46-3764-4320-93aa-4c3fb51e01be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pand...@gmail.com

unread,
Feb 15, 2018, 11:39:37 AM2/15/18
to Prometheus Developers
Thank you Matthias. I was under the impression that I could simply replace the default instance label with an alternate label available from a different metric, in this case node-exporter service's 'node_uname_info.nodename' label.

I don't want to relabel a metric, just override instance with something already being scraped.

To confirm, this is not possible, right? (I understand that tagging w/hostname is likely my next course of action)

Matthias Rampke

unread,
Feb 16, 2018, 3:37:56 AM2/16/18
to pand...@gmail.com, Prometheus Developers
Correct. Relabelling can only access metadata of the target, metric relabelling can only access the labels of the same metric.

/MR

Reply all
Reply to author
Forward
0 new messages