relabel_configs

97 views
Skip to first unread message

David Friedman

unread,
Jun 7, 2022, 3:05:11 AM6/7/22
to Prometheus Users
Hi all
I'm trying to relabel a label from tag_name to just name 
I tried to do something like this 
            - action: labelmap
              regex: "[^_]+_(.+)"
              replacement: "$1"
but it didn't work
any help would be appreciated
thanks 

Brian Candler

unread,
Jun 7, 2022, 3:37:49 AM6/7/22
to Prometheus Users
Define "didn't work" - what actually happened?  Can you show some examples?

Where are you doing this: inside a relabel_configs block, or a metric_relabel_configs block, or somewhere else?  What version of Prometheus?  Did you reload/HUP prometheus after changing the config?

I believe you'll get both old and new labels, unless you also have a labeldrop rule for the old ones.

David Friedman

unread,
Jun 7, 2022, 4:24:19 AM6/7/22
to Prometheus Users
Hi thanks for the respond 
so nothing happened the label stayed the same
I have it in a  relabel_configs block 
Prometheus version is:  2.32.1
and ill add a labeldrop once i get both labels 
thanks

Ben Kochie

unread,
Jun 7, 2022, 4:55:33 AM6/7/22
to David Friedman, Prometheus Users
That won't work because labelmap needs a `source_labels` to act on.

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/130e874a-4961-412b-9619-99817ceb527dn%40googlegroups.com.

David Friedman

unread,
Jun 7, 2022, 5:35:29 AM6/7/22
to Prometheus Users
did this and got an error "mapping values are not allowed in this context"
          relabel_configs:
            - source_labels [tag_Customer]
              action: labelmap
              regex: "[^_]+_(.+)"
              replacement: "$1"

Brian Candler

unread,
Jun 7, 2022, 6:23:01 AM6/7/22
to Prometheus Users
You are missing a colon after "source_labels".

Brian Candler

unread,
Jun 7, 2022, 6:30:51 AM6/7/22
to Prometheus Users
On Tuesday, 7 June 2022 at 09:55:33 UTC+1 sup...@gmail.com wrote:
That won't work because labelmap needs a `source_labels` to act on.

No, I don't believe that's true. I've just tested the following and it works fine:

    relabel_configs:
      - action: labelmap
        regex: "(__address__)"
        replacement: "dummy$1"

Metrics now have an extra "dummy__address__" label.

What I suspect is happening here is that the OP is using relabel_configs when they should be using metric_relabel_configs.

* relabel_configs is applied *before* the scrape takes place. It can therefore only affect labels which are returned by the service discovery.
* metric_relabel_configs is applied *after* the scrape takes place.  It processes all the metrics returned by the exporter, and therefore can see labels which the exporter itself has generated.

David Friedman

unread,
Jun 7, 2022, 7:06:16 AM6/7/22
to Prometheus Users
Yes "metric_relabel_configs" worked for me
thanks for all the help!!!

Reply all
Reply to author
Forward
0 new messages