Grafana Alerts: different conditions for different labels?

189 views
Skip to first unread message

Or Fins

unread,
Jul 7, 2021, 3:49:12 AM7/7/21
to Prometheus Users
Assuming I have a counter with 3 different labels, how can I create an alert with a different condition for each of the labels, without splitting the query into 3?

So instead of 3 queries like this:rate(my_counter{mylabel=1}[30s]) I’d like to use just a single query: rate(my_counter[30s]), and create different conditions for mylabel=1, mylabel=2, mylabel=3. Is it possible?

Grafana v7.1.5 (9893b8c53d)

Stuart Clark

unread,
Jul 7, 2021, 4:16:43 AM7/7/21
to Or Fins, Prometheus Users
You can use a regex match (=~ instead of =) to match all three of the
values in a single query.

--
Stuart Clark

Or Fins

unread,
Jul 7, 2021, 4:40:29 AM7/7/21
to Prometheus Users
Thank you but it's not what I meant (I think). To make it clear, what I meant is instead of this:
not_1.png
not_2.png
I'd like to do something like this:
this_1.png
this_2.png
In the first one I separate the conditions by query, and in the second one I want to separate by label value. Is this possible?

Stuart Clark

unread,
Jul 7, 2021, 4:56:57 AM7/7/21
to Or Fins, Prometheus Users
On 2021-07-07 09:40, Or Fins wrote:
> Thank you but it's not what I meant (I think). To make it clear, what
> I meant is instead of this:
>
> I'd like to do something like this:
>
> In the first one I separate the conditions by query, and in the second
> one I want to separate by label value. Is this possible?
>

That sounds like a Grafana specific question, so while there are
probably some people on this mailing list who might know I'd also
suggest posting to one of the Grafana lists...

--
Stuart Clark

Or Fins

unread,
Jul 7, 2021, 4:59:07 AM7/7/21
to Prometheus Users
In the meantime I posted to community.grafana.com . What are the Grafana lists?

sayf eddine Hammemi

unread,
Jul 7, 2021, 5:20:11 AM7/7/21
to Or Fins, Prometheus Users
Hello, You can store your thresholds in a metric that has the same values of that label, that way you can compare on that label in only one query, look at this https://www.robustperception.io/using-time-series-as-alert-thresholds

--
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/2a73d53d-4cdd-48ba-aeef-d00ad7ff0f73n%40googlegroups.com.

Or Fins

unread,
Jul 7, 2021, 5:29:17 AM7/7/21
to Prometheus Users
Thank you, but how can I implement this in Grafana?
Reply all
Reply to author
Forward
0 new messages