Difference on counter per time range

19 views
Skip to first unread message

Marcos F. Lobo

unread,
Jun 11, 2020, 2:42:41 PM6/11/20
to Prometheus Users
Hi all,

I have a metric in my application (using micrometer) and I have a counter that increases each time a method is executed. Of course, this counter is reset only if the app is restarted.

This metric is exposed to Prometheus and I can query it in the UI.

Now the question. Is there a way to get a difference on that counter between 2 dates?

Use case:
- Today, the counter has value 5000
- 2 days ago, it had value 4000
- So, I need a query that displays the value 1000, which is the difference between the 2 dates.

Thank you for your time.

Regards,
Marcos

Brian Candler

unread,
Jun 13, 2020, 2:54:20 AM6/13/20
to Prometheus Users
foo - foo offset 2d

However if you want counter resets to be taken into account, you may prefer to use increase():
increase(foo[2d])

Note that increase() takes the rate and extrapolates over the full 2d period, so won't exactly line up with the counter values.

Marcos F. Lobo

unread,
Jun 18, 2020, 2:35:02 AM6/18/20
to Prometheus Users
Hi Brian,

Thank you for the answer, I'll give it a try, it looks it's what I was looking for.

Regards,
Marcos.
Reply all
Reply to author
Forward
0 new messages