What is the definition of $value in an alert template?

23 views
Skip to first unread message

Alex Rosen

unread,
Apr 17, 2020, 7:46:01 AM4/17/20
to Prometheus Users

This page says: "The $value variable holds the evaluated value of an alert instance."

It would be great if this also included a more explicit definition, because this definition isn't obvious to me. For example, if I have:


expr: sum(increase(some_counter[3h])) by (foo) < 1


Which part of this is the $value? It can't be the entire expression, because that's just a boolean value. Is it everything to the left of the comparison operator?


Brian Brazil

unread,
Apr 17, 2020, 7:53:11 AM4/17/20
to Alex Rosen, Prometheus Users
On Fri, 17 Apr 2020 at 12:46, Alex Rosen <alexr...@gmail.com> wrote:

This page says: "The $value variable holds the evaluated value of an alert instance."

It would be great if this also included a more explicit definition, because this definition isn't obvious to me. For example, if I have:


expr: sum(increase(some_counter[3h])) by (foo) < 1


Which part of this is the $value? It can't be the entire expression, because that's just a boolean value.

Alerts aren't booleans, every series that the alert expression returns becomes an alert instance. So in the above expression the values of the alerts would be the sum() - if any of them are smaller than 1.


--

Brian Candler

unread,
Apr 17, 2020, 8:43:25 AM4/17/20
to Prometheus Users
It *is* the value of the entire expression.

The prometheus operator "a < b" gives the value of the left-hand side if it's less than b (scalar, or timeseries with exactly matching label set), or no result if not.  See comparison operators.

You can try this for yourself in the PromQL expression evaluator in the prometheus UI: e.g.

rate(node_network_receive_bytes_total[2m]) > 10000

You'll see line segments where the condition is true, and gaps where it's false.

png1.png


 
There is another form: "a < bool b", which gives 0 for false and 1 for true.  In that case, the timeseries always exists, and $value will be either 0 or 1 (which for alerts makes it less useful in annotations)

Alex Rosen

unread,
Apr 18, 2020, 5:24:25 AM4/18/20
to Prometheus Users
Ah, that makes sense! Thanks for the explanation, I'm new to Prometheus so it wasn't obvious to me.

If it helps the next newbie, I made a pull request to add a bit more explicit documentation about this, to clarify the parts that confused me: https://github.com/prometheus/prometheus/pull/7141
Reply all
Reply to author
Forward
0 new messages