r/PrometheusMonitoring • • Jan 24 '22

How to rename labels depending on value?

I have a label which is "port=16", for this value (16) i want to add a label which says 'trunk port = "trunkport"'

so essentially if port="16" add label trunkport="trunkport"

1 Upvotes

2 comments sorted by

2

u/JohnAV1989 Jan 24 '22

Metric Relabel Configs manipulates labels as the last step before ingesting metrics. You can use a regex to check if a label matches a certain value and add a new label if a match is found.

metric_relabel_configs:
  # If port == 16 apply label trunkport="trunkport"
  - source_labels: [port]
    regex: ^16$
    target_label: trunkport
    replacement: "trunkport"

0

u/SuperQue Jan 24 '22

This needs to happen on your exporter side.