substring of label values from recording rules

126 views
Skip to first unread message

ishu...@gmail.com

unread,
Sep 29, 2023, 9:16:22 AM9/29/23
to Prometheus Users
Hello,

I have a question and could not get my head around it. may be if someone can help. 

I have a recording rule the records rate of api requests for last 5 minutes. But there are some api requests for which I want the api path to be stripped only with the first two levels. 

for example:
/test/download/12345 and /test/download/56789 , both these should be stripped to /test/download and the last part to be removed in the labels. As the last part is dynamic, i want the recording rules to record only the first two levels i.e /test/download as label value.

Thanks in advance



Matthias Rampke

unread,
Sep 29, 2023, 10:15:50 AM9/29/23
to ishu...@gmail.com, Prometheus Users
You can do this by first using `label_replace` to create a new(!) label with the path prefix. Something like

count by(host) (label_replace(up, "host", "$1", "instance", "([^:]+)(:[0-9]+)"))

However keep in mind that you are still incurring the storage cost of all these raw metrics. It may be worthwhile to fix this further up the chain in the app that exposes this data to begin with.

/Matthias

--
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/ef84f03a-0f37-4ac2-adac-5a6b42e4bb34n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages