I am currently in the process of creating a monitoring system for a Counter-Metric. An alarm is to be fired as soon as the value of an increase exceeds a threshold. I have got the panel to work (see following picture)
Expression:
increase(metric_call_total[$__range])
The next step was to create an alarm for this. Here I am faced with the problem that Grafana only allows relative time values as a range (e.g. last 1h, last 2h, last 24h, etc.). grafana time range
However, I would need a range from 00:00 to now to be able to use the increase properly.
I have already tried to map this with promql, but without success.
Have any of you had the same problem and a solution?
Thank you very much
Expected outcome: Increase Value from 00:00 to now
Try the following PromQL:
increase(
(metric_call_total and (
floor(timestamp(metric_call_total @ end()) / (24*3600))
== on() group_left()
floor(vector(time() / (24*3600)))
))
[1d:5m]
)
It should return metric_call_total
increase for the current day starting from 00:00 UTC. You can adjust timezone offset by adding it to the time()
before dividing it by (24*3600)
.
This query uses subquery feature for filtering out metric_call_total
samples before 00:00 UTC, so they are ignored when calculating increase().
The query uses @
modifier together with end() function for calculating the timestamp() for the current day. This timestamp is then compared to the time() calculated per every 5 minutes over the last 24 hours. This filters out samples from the previous day by UTC.
The query also uses on
modifier together with group_left
modifier in order to match series at the left side of ==
with timestamp values at the right side.
The floor() function is used for rounding the division result to Unix day.