relabeling by metrics name

1,116 views
Skip to first unread message

antonios....@gmx.de

unread,
Mar 12, 2018, 3:06:32 PM3/12/18
to Prometheus Users
Hi,


i try to rename the label "env" to "node_env" for the metric "machine_cpu_cores", but the regex does not work.

i added on my prometheus.yml the folowing lines:
relabel_configs:
...
   
-   action: replace
        regex
: .*machine_cpu_cores.*
        source_labels
:
       
- env
        target_label
: node_env


The replacement only works if the regex-part is commented out, but then it replaces every metric.
I also tried regex: machine_cpu_cores and a lot of other regex-matches.


What am i doing wrong here?


Best,
Toni.

Brian Brazil

unread,
Mar 12, 2018, 3:23:27 PM3/12/18
to antonios....@gmx.de, Prometheus Users

Antonios Dimtsoudis

unread,
Mar 13, 2018, 5:59:44 AM3/13/18
to Prometheus Users
Hi again,

i also tried out metric_relabel_config.

It only works without the regex line. This is strange somehow, since there are so many other examples.

Brian Brazil

unread,
Mar 13, 2018, 3:12:45 PM3/13/18
to Antonios Dimtsoudis, Prometheus Users
On 13 March 2018 at 09:59, Antonios Dimtsoudis <antonios....@gmx.de> wrote:
Hi again,

i also tried out metric_relabel_config.

It only works without the regex line. This is strange somehow, since there are so many other examples.


Try:
- source_labels: [__name__, env]
  regex: 'machine_cpu_cores;(.*)'
  replacement: '${1}'
  target_label: node_env


This lets you have a condition on __name__ while capturing the value of env.

Brian

 



Am Montag, 12. März 2018 20:23:27 UTC+1 schrieb Brian Brazil:
On 12 March 2018 at 19:06, <antonios....@gmx.de> wrote:
Hi,


i try to rename the label "env" to "node_env" for the metric "machine_cpu_cores", but the regex does not work.

i added on my prometheus.yml the folowing lines:
relabel_configs:
...
   
-   action: replace
        regex
: .*machine_cpu_cores.*
        source_labels
:
       
- env
        target_label
: node_env


The replacement only works if the regex-part is commented out, but then it replaces every metric.
I also tried regex: machine_cpu_cores and a lot of other regex-matches.


What am i doing wrong here?



--

--
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-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/4e9ad517-89cf-4b88-b543-e0e60653259d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages