'Is there a way to use a Prometheus counter with a holt_winters function call?

In the Prometheus documentation it describes the holt_winters() function that can be used generate a smoothed curve.

However the documentation states it should only be used with Gauges. (Obviously I could use it with a counter bu then I just get a smoothed line that is always going up, not terribly useful)

I would like to leverage the holt_winters() function against a counter like http_request_total.

Something like;

holt_winters(rate(http_request_total[5m])) by (path)

Is this possible? Or is there a better way to approach this?



Solution 1:[1]

You need to use a recording rule to store the result of the rate, see https://www.robustperception.io/composing-range-vector-functions-in-promql/

Solution 2:[2]

It is possible to pass rate() into holt_winters() by using Prometheus subqueries:

holt_winters(
  (sum(rate(http_request_total[5m])) by (path))[1h:1m], 0.5, 0.5
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 brian-brazil
Solution 2 valyala