6
votes

Is there a way to make a Prometheus counter in Grafana truly monotonic?

The counters on my server (using the Prometheus Java library) get reset whenever the server is restarted and the counter drops to zero in Grafana too. I cannot find a way in the documentation for Prometheus queries. Neither does the Java library provide a way to make a Counter persistent over restarts.

2
Did you find a solution on how to return a monotonically increasing value from a counter? - jeroentbt
No, I didn't :( - raimohanska

2 Answers

5
votes

With counters, you almost never care about the value itself, but only about its rate of increase. Thus, counters are always meant to be used in combination with the rate() or increase() functions. These functions handle counter resets for you (any non-monotonic increase will be treated as a counter reset and neutralized in the rate calculation).

1
votes

The way to approach this is to use the rate function, which handles counter resets.