Jananath Banuka
Jananath Banuka

Reputation: 3973

How to filter using Grafana queries

So I have a grafana dashboard and I need to filter out some labels. So I am using label_values function.

My data source is prometheus

So, to this label_values function, i am passing a variable domain_name and it produces 3 results as:

domain1
domain2
domain3

But I need to only filter and get the domain1, so domain2 and domain3 are removed.

So I tried these and it says expressions are invalid.

// 1 method, gives invalid expression error
label_values(domain_name)[0]

// 2 method, gives invalid expression error
label_values(domain_name[0])

So How can I do this?

Here attached a screenshot as well.

enter image description here

Upvotes: 0

Views: 5239

Answers (1)

trallnag
trallnag

Reputation: 2386

Your question is a bit hard to understand. So here are two answers:

You want only domain1 to end up in the template variable:

label_values(my_metric{my_label="domain1"}, my_label)

I cannot imagine a reason why you would want this. So I assume you actually want to filter your dashboard / panels for this specific domain.

You want to filter dashboard / panels for a specific domain:

label_values(my_metric_that_has_label_with_all_domains, domain_label_name)

Don't forget to set update on time range change.

Now in a panel you can use the variable like this:

rate(mymetric{domain_label_name=~"$cluster"}[5m])


Examplary usage

enter image description here

Upvotes: 1

Related Questions