'How to calculate the instant rate of a gauge metric?

How can I calculate the per-second instant rate of increase of the time series in Prometheus or Grafana without using rate() or irate()?

This drive function is not helping to achieve the same result as irate

irate(node_cpu_seconds_total[5m]) 

deriv(node_cpu_seconds_total_gauge[5m]) 

Actually I need to calculate the per-second instant rate of increase of the time series of Gauge metric data which is a modified counter metric type data.



Solution 1:[1]

You can use deriv() for that. Here is an example:

deriv(process_virtual_memory_bytes{job="$job", instance="$instance"}[$__interval])

enter image description here

Solution 2:[2]

Prometheus doesn't provide irate() equivalent for gauge time series :(

If you still need it, then try ideriv function from VictoriaMetrics. It returns the derivative based on two last samples for the time series:

ideriv(metric_name[5m])

Note that both irate() and ideriv() functions don't capture spikes, since they perform calculations based on a subset of raw samples, while ignoring the rest of samples. See this article for details. If you need capturing spikes, then take a look at rollup_deriv function. It reliably captures min, max and avg derivative based on all the raw samples, which hit the given lookbehind window in square brackets.

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 trallnag
Solution 2 valyala