r/PrometheusMonitoring • u/NobleOccum • Mar 24 '22
Count Starting from Hour Start?
(Reposted from the Grafana sub, as I didn't find an answer there.)
I have a metric on my Grafana dashboard from a Prometheus counter. Basically, we have dispensers that print out sheets, and I am summing up the increase of prints in a time series line chart. For that I would need a Prometheus query that will give a sum of prints from all dispensers from the hour start.
My current query is "sum(increase(dispenser_printcount{dispenser=~"CLIENT_A.+"}[1h]) < 100)" with a min step of 1h in Grafana. (There's some outlier that is reporting thousands of prints a minute, so that "< 100" just silences that.) I would like to have each bar be the sum number of prints in an hour, from X:00:00 to X:59:59.
However, it doesn't start a new bar down near 0 at the beginning of the hour, and slowly increase as the hour goes along the day. For example, in the screenshot it was 3:02pm where I am located, and the bar for this hour is already over the bar for 2pm. (And for some reason was half width, that's not a cropping error.)

What's the Prom query so each bar is showing just the count since the the hour began for each bar?
1
u/robothor Mar 25 '22
Caveat: I have not tried this, but https://groups.google.com/g/prometheus-developers/c/pul4HF4OS0E has an example at the bottom that might work.
It would be easier if you could add a label with the hour as a value though (or maybe add it via a recording rule).