As the title says, I am looking for a way to get the maximum value of a time series, which resets daily. After this task is achieved I would like to create a sum over those values to get a value per month/year. What is the best way to achieve this in Prometheus?
Asked
Active
Viewed 1.1k times
1 Answers
8
As described in my post on prometheus-developers, here is a possible option, although it's far from readable:
up{job="prometheus"} + ignoring(year, month, day) group_right
count_values without() ("year", year(timestamp(
count_values without() ("month", month(timestamp(
count_values without() ("day", day_of_month(timestamp(
up{job="prometheus"}
)))
)))
))) * 0
Replace both instances of up{job="prometheus"}
with whatever series selector you need. No idea how efficient this is, though. :o)

Alin Sînpălean
- 8,774
- 1
- 25
- 29
-
1Could you explain what is the idea behind this? Thanks for the solution anyway – Benibr Feb 01 '21 at 19:02
-
1The whole point of the `count_values_without(...)` block is to get a time series with the same labels plus `year`, `month` and `day`as the original time series (and a garbage value). Then you do `+ ignoring(year, month, day) group_right
* 0` in order to attach the `year`, `month` and `day` labels to the original time series' value. Now that this new time series has labels that identify each day, you can aggregate by day whichever way you want by filtering by those labels. – Alin Sînpălean Feb 02 '21 at 10:44 -
if we assume `up{job="prometheus"}` is a counter...would I just wrap the above around `sum(increase( what-you-have-above ))` to graph it? when I do that...I get an error `Error executing query: invalid parameter 'query': 2:3: parse error: expected type range vector in call to function "increase", got instant vector` – lightweight Mar 19 '21 at 16:28
-
I should have said "replace both instances of `up{job="prometheus"}` with whatever *expression* you need aggregated by date`. So you'd need `sum(increase(your_counter[5m]))` to appear twice in the query above (replacing `up{job="prometheus"}`). – Alin Sînpălean Mar 19 '21 at 21:05