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?
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)
I just wanted to add to the excellent answer by Alin Sînpălean. He splits the data into time series per day. You can similarly split them per month and then use the Grafana reduce "series to rows" transform to calculate the total per month. You need another sort transform to get the rows back in order. This only works well when you add a leading zero to the month number. Then you can use "{{year}}-{{zero}}{{month}}" as your legend which sorts correctly.
label_replace(
up{job="prometheus"} + ignoring(year, month) group_right
count_values without() ("year", year(timestamp(
count_values without() ("month", month(timestamp(
up{job="prometheus"}
)))
))) * 0,
"zero",
"0",
"month",
"^[0-9]$"
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With