Showing data of counter from midnight till now

Viewed 1984

My application contains some counter which always increase and never being reset.

I use prometheus together with grafana. What I need is to show counter changes related to each day, another words I need to take data of counter from midnight till now. So for instance I could see the month graph and check how counter was changed every day.

In grafana I use promql queries and I have this query

enter image description here

It works good, but it can handle the data from previous days, which doesn't fit me. What I would like to have is something like increase(Counter[from 'midnight' - to 'now']), but I'm not sure how to build such query.

1 Answers

If a single value (i.e. stat panel) fits your needs, you can make it like this: how to

now/d is Grafana special time value "This day so far". If used together with $__range variable it becomes the number of seconds since the beginning of the day.

This setup will only work for instant queries, as the range is not adjusted for every data point on the panel. Thus, you can only get one valid value out of this. The datapoints on a graph panel will use the same number of seconds and thus, it will calculate increase() taking some values from the previous day.

If you wish to see other possible Grafana time placeholders (such as now/d), see this page.

Related