Force lowercase using label_replace

1,177 views
Skip to first unread message

thibaut allain

unread,
Nov 23, 2021, 3:19:54 AM11/23/21
to Prometheus Users
Hello,

I need to lowercase the hostname of my metrics. 

I would like to use the function label_replace as below. The idea here is to create a new field called "host" that forces the lowercase of the "hostname "field. Is it possible to use the regex (here "[[LOWER]]") to do this ? 

sum without (hostname) (label_replace(up{instance="x.x.x.x:9100"}  * on (instance) group_left(hostname) sophosav_linux_started, "host", "${1}", "hostname", "[[LOWER]]"))

Thanks for your answer

Brian Candler

unread,
Nov 23, 2021, 8:31:07 AM11/23/21
to Prometheus Users
AFAIK this isn't possible.  The things you *can* do with label_replace are given here:
The replacement value is just a string which can have $1, $2 etc in it.

Julius Volz

unread,
Nov 23, 2021, 2:21:22 PM11/23/21
to Brian Candler, Prometheus Users
In case the proposed "template" relabeling action in https://github.com/prometheus/prometheus/issues/9637#issuecomment-970327987 makes it into Prometheus, it's conceivable that there could be various functions that are made available to the template code that could e.g. include lower-casing.

--
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/c6cc019c-fea3-46a0-9a0d-5ea144a71ea3n%40googlegroups.com.


--
Julius Volz
PromLabs - promlabs.com
Reply all
Reply to author
Forward
0 new messages