About sum(rate…) in Prometheus

Jan 17, 2023
  • You can’t do the rate of a sum because you can’t use range selectors (i.e. [5m]) on the output of a function; as rate takes a range vector and one would write rate( sum(http_requests_total)[5m] ) the query is not allowed
  • Using subqueries one can still compute the rate of a sum
  • Doing so is discouraged anyway because if a server restarts and that causes a counter resets the sum over all the counter will be lower and rate will show a decrease for the metric, which didn’t happen
  • If you instead take the single rates counter resets won’t show (at least not for more than 1 time window) and your graph will no longer show a decrease for the metric if it didn’t happen

Ref: https://www.robustperception.io/rate-then-sum-never-sum-then-rate/

--

--

No responses yet