The sum(rate(m[d]))
doesn't return the increase of m
over the duration d
. It returns the summary average increase rate over the lookbehind window d
for all the counter metrics m
:
If you need obtaining the increase for counter metric over the last hour (see 1h
in square brackets), then use the following query:
increase(vector_component_sent_events_total[1h])
This query uses increase() function for calculating the increase of the provided counter over the specified time range in square brackets. This function calculates the increase individually per each input time series.
If you need summary increase over the last hour for multiple time series, then wrap the query above into sum():
sum(increase(vector_component_sent_events_total[1h]))
Prometheus may return fractional or incomplete results from increase() over integer counter because of the following issues:
- Extrapolation issue.
- Prometheus ignores the increase between the last raw sample just before the lookbehind window passed to
increase()
in square brackets and the first raw sample inside the lookbehind window.
If you need exact m
counter increase over some duration d
, then m - (m offset d)
query may work. But it returns incorrect results in the following cases:
- When
m
counter resets to zero on the given lookbehind window d
. This usually happens on the restart of the application, which exports the counter metric.
- When some counter matching
m
appears inside the lookbehind window d
. This usually happens when new entity with the associated counter appears in the application.
Prometheus doesn't provide working solution for these issues :(
P.S. If you still want consistently obtaining exact increase for counter metric over some lookbehind window, then try VictoriaMetrics - this is Prometheus-like monitoring solution I work on. Its' increase() function is free from issues mentioned above.