Results binned by hour from prom & increase()

I’m trying to produce a bar chart based on each hour in a day of how much electricity was used in that hour.

Prometheus can synthesize that data quite nicely; I use


However, when I choose a time range (e.g: “Yesterday”), there are some problems.

The first result, for time 00:00, is not the increase from 00:00->01:00, but from the previous day’s 23:00->00:00. This is down to the definition if increase().

I can slightly hack around this by adding a time offset (0h+1h, as future offsets don’t seem to be supported). This does skip the first result, at the expense of a ‘time shift’ label in the window. However, the time axis reports it as 01:00, which is a bit confusing; I want it really to be ‘00:00’ (or even ideally 00h->01h). This is sort of important as I want to use the time for a drill-down link later on.

The second problem is that if I use the quick selection of ‘Yesterday’ as a time range, I actually get 25 results not 24, as the to= value is inclusive not exclusive in the prom query.

I can’t see an easy way of fixing this; the behaviour of increase() is sort of outside grafana’s control. My next best idea is to proxy the prometheus data source to manipulate the data before it gets to the grafana panel (e.g: tweaking date ranges, re-writing the times). I don’t know if there are plugins or other projects that help with this?

Is there any other way I might coax prom+grafana into the output I’m looking for?

Negative offset is supported in MetricsQL, so something like increase(metric[1h] offset -1h) should work there.