Using another query in alerts description

25 views
Skip to first unread message

Yashar Nesabian

unread,
Jul 14, 2020, 4:28:13 AM7/14/20
to Prometheus Users
Hi
I have an alert which fires when a CPU temperature is in the critical state:
ipmi_temperature_state{id="21",name="02-CPU 1"} == 2
And I have another metric which shows the temperature of this CPU:
ipmi_temperature_celsius{id="21",name="02-CPU 1"}
I wonder if it is possible to print the output of the second metric when the alert fires?







Brian Candler

unread,
Jul 14, 2020, 4:53:29 AM7/14/20
to Prometheus Users
Since the labels are the same, this is straightforward:

expr: ipmi_temperature_celsius and (ipmi_temperature_state == 2)

The $value of the alert is now ipmi_temperature_celsius - but the value will only be passed through if there is a matching RHS timeseries (with any value, but in this case it's filtered so that the RHS timeseries is filtered out unless the value is 2).  

PromQL expressions with comparison operators are like filters.  For example:

expr: ipmi_temperature_celsius > 40

is not a true/false, but rather it passes through timeseries where the value is > 40, and excludes timeseries where the value is <= 40.

See:

Yashar Nesabian

unread,
Jul 14, 2020, 5:17:16 AM7/14/20
to Prometheus Users
Thanks Brian, this solved my problem

Julien Pivotto

unread,
Jul 14, 2020, 5:39:38 AM7/14/20
to Yashar Nesabian, Prometheus Users
Yes:


Simple answer:

Use:
ipmi_temperature_celsius and (ipmi_temperature_state == 2)

as alerting query

and use "{{$value}}"

Complex answer (please don't use):

{{ $q := printf "ipmi_temperature_celsius{id='%s',name='%s'}" $labels.id $labels.name}}·
{{ with query $q }}
{{ . | first | value | humanize }}
{{ end }}

https://prometheus.io/docs/prometheus/latest/configuration/template_examples/

>
>
>
>
>
>
>
> --
> 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/1a2d49e8-4692-4e56-92ec-b1389afff8d3o%40googlegroups.com.


--
Julien Pivotto
@roidelapluie
Reply all
Reply to author
Forward
0 new messages