6

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

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

  • .+ (as a custom All variable)
  • eu.+
  • us.+

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?

0

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

are you sure that you can apply regex to variables using ":" ?
=~"${variable:pipe}" instead of using ":", ref @smaiakov
0

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", ...}

1 Comment

thanks for the answer - am already doing that, I'll update the example query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.