Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I filter the result of label_values(label) to get a list of labels that match a regex?

I have several metrics with the label "service". I want to get a list of all the "service" levels that begin with "abc" and end with "xyz". These will be the values of a grafana template variable.

This is that I have tried: label_values(service) =~ "abc.*xyz"

However this produces a error Template variables could not be initialized: parse error at char 13: could not parse remaining input "(service_name) "...

Any ideas on how to filter the label values?

like image 427
Moe Avatar asked May 02 '19 18:05

Moe


People also ask

What regex does Grafana use?

The regex type is based on Golang as the backend code is written in Go while the Frontend is in Typescript.

What query language does Grafana use?

PromQL is a functional query language that lets users select and aggregate time series data in real time.


1 Answers

This should work (replacing up with the metric you mention):

label_values(up{service=~"abc.*xyz"}, service)

Or, in case you actually need to look across multiple metrics (assuming that for some reason some metrics have some service label values and other metrics have other values):

label_values({__name__=~"metric1|metric2|metric3", service=~"abc.*xyz"}, service)
like image 80
Alin Sînpălean Avatar answered Oct 22 '22 08:10

Alin Sînpălean