Rename instance in metrics on disk

557 views
Skip to first unread message

Samuel Mutel

unread,
Sep 9, 2021, 7:51:20 AM9/9/21
to Prometheus Users
Hello,

I just changed my prometheus config to relabel metrics before storing them on the disk.

However I would like to rename instance name (from simple name to FQDN) in the metrics already saved by prometheus on the disk.

I assume that I need to use promQL with the prometheus editor but I didn't find on internet the good query to execute.

Example:

Rename this:
node_timex_frequency_adjustment_ratio{address="XX.XX.XX.XX", instance="consul:9100", job="consul", service="node-exporter"}

Into this:
node_timex_frequency_adjustment_ratio{address="XX.XX.XX.XX", instance="consul:9100", job="consul.toto.com", service="node-exporter"}

Thanks.

Brian Candler

unread,
Sep 9, 2021, 8:22:11 AM9/9/21
to Prometheus Users
job is the name of the scrape job, not the name of the host being scraped.  Generally, many hosts are scraped with the same scrape job.

What you want to set is the *instance* label:  i.e. instance="consul.toto.com"

The way to do it is using service discovery relabelling (not metric relabelling). See:

As far as I'm aware, you can't change metrics which are already saved to disk, unless you export them all and reimport them (using the recently-added backfilling functionality), and then delete the old timeseries.  It would be an interesting feature to be able to change the labels on an existing timeseries, but I haven't seen it mentioned anywhere.

Samuel Mutel

unread,
Sep 10, 2021, 3:40:29 AM9/10/21
to Brian Candler, Prometheus Users
Hello,

Thank you for your response. However I have already this config part:

- source_labels: ['__meta_consul_node', '__meta_consul_service_port']
        target_label: 'instance'
        regex: '([^:]*);(.*)'
        replacement: '${1}.toto.com:${2}'
        action: 'replace'

It is working for new metrics in prometheus. My question is focus on metrics already saved on disk.

Thanks. Regards.

--
You received this message because you are subscribed to a topic in the Google Groups "Prometheus Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/prometheus-users/4BDu_spHVM0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/49c6c965-0b49-43a3-8db6-7372485393cdn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages