promql to cut label name

21 views
Skip to first unread message

ishu...@gmail.com

unread,
Nov 10, 2020, 9:32:05 AM11/10/20
to Prometheus Users
Hi,

I have a query with promql. I have prom sd configuration to scrape metrics from my kube cluster. I want to know if it is possible to cut string and apply it as label name.

My project has test01, test02 and preprod environments but namespaces will be test01-internal, test02-internal, prodref-internal and prodref-external .Because of prometheus sd config the env is coming as test01-internal where i want only test01. Is it possible to extract only this string and using replace i can send this as env label.

Thanks
Eswar

Stuart Clark

unread,
Nov 10, 2020, 10:22:16 AM11/10/20
to ishu...@gmail.com, Prometheus Users
Yes you can do that with relabeling.

Use a regular expression match, with a () around the bit you want to
keep. That will then be stored in $1, which is the default already for
the "replacement:" field.


https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config

Reply all
Reply to author
Forward
0 new messages