Jatinder Singh Brar
Jatinder Singh Brar

Reputation: 431

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.

Upvotes: 3

Views: 11987

Answers (2)

valyala
valyala

Reputation: 17800

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.

Upvotes: 1

trallnag
trallnag

Reputation: 2376

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

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

enter image description here

Upvotes: 5

Related Questions