Renaming Harvest Labels Using Prometheus Relabeling Configurations #2762
rahulguptajss
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
To duplicate a label in Prometheus, add the
metric_relabel_configs
to the appropriatescrape_configs
section in yourprometheus.yml
. This allows you to copy the value of an existing label to a new label, while keeping the original label intact.Here's an example of how to copy the
aggr
label to a new label calledaggregate
:Be sure to replace
your_job_name
with the actual name of the job for which you want to apply the label duplication. This configuration will result in bothaggr
andaggregate
labels being present on the metrics, withaggregate
having the same value asaggr
.After updating your
prometheus.yml
file, restart prometheus to apply the changes.Example:
Before applying
metric_relabel_configs
:The original metric looks like this:
After applying
metric_relabel_configs
:Once you've updated the configuration and restarted Prometheus, the metric will now include both the original
aggr
label and the newaggregate
label with the same value:Notice that the metric now has an additional label
aggregate
with the value"test1"
, which is the same as theaggr
label's value.Note:
Keep in mind that
metric_relabel_configs
only affects the labels as they are scraped and ingested by Prometheus. It does not change the labels in the historical data already stored in Prometheus. You will only see the newaggregate
label on data scraped after the configuration change and restart.Beta Was this translation helpful? Give feedback.
All reactions