danp
danp

Reputation: 15241

Passing regexes to prometheus query via grafana variables

I'm trying to pass custom variables to prometheus via grafana variables.

The values I've got setup in grafana are as follows:

The variables are used in a query such as:

some_metric{availability_zone=~"$az", ...}

The All variable works as expected, and the raw eu-.+ values etc when put directly into the query also work fine - but when the variable is assigned via a dropdown, no metrics are returned. eg:

some_metric{availability_zone=~"eu.+", ...}

..correctly matches all metrics with labels such as availability_zone="eu-west-1"

custom variable setup in grafana

I've tried escaping and without in the custom values, but in for both of the custom values no metrics are returned.

What is wrong here?

Upvotes: 6

Views: 3665

Answers (2)

devzero
devzero

Reputation: 2680

The way to do this seems to be:

some_metric{availability_zone=~"${az:pipe}", ...}

The two "gotchas" being that you need regex comparison "=~" and the ${variable:pipe} to get the regex to run.

Upvotes: 6

Oliver
Oliver

Reputation: 12981

To make PromQL use regular expressions when matching labels, you have to use =~ instead of =.

Your query should look something like this:

some_metric{availability_zone=~"$az", ...}

Upvotes: 0

Related Questions