Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get delta between two custom timestamps in Prometheus

I have a Prometheus metric called device_number. What I want is to show the difference in value between now and one day/week/month etc ago. Which means subtracting two values with two different timestamps. Checking around I don't find any useful documentation on how to do it.

Something I would do, but doesn't work is:

sum(device_number) - sum(device_number[$__range])
like image 915
Matej Avatar asked May 15 '19 11:05

Matej


People also ask

What is Delta in Prometheus?

delta() delta(v range-vector) calculates the difference between the first and last value of each time series element in a range vector v , returning an instant vector with the given deltas and equivalent labels.

What is range vector in Prometheus?

Prometheus Data Types Range Vector : A range vector is a set of time series containing a range of data points over time for each time series. Unlike an instant vector which returns one sample per time series, a range vector can return many samples for each time series.

What is rate query in Prometheus?

Prometheus rate function is the process of calculating the average per second rate of value increases. You would use this when you want to view how your server CPU usage has increased over a time range or how many requests come in over a time range and how that number increases.

What is irate PromQL?

irate() ("instant rate"): This calculates the rate of increase per second just like rate() , but only considers the last two samples under the provided time window for the calculation and ignores all earlier ones.


1 Answers

I found offset is the correct keyword.

Query like this:

sum(vss_device_number) - sum(vss_device_number offset 1d)

Will return difference between now and yesterday.

Docs.

like image 154
Matej Avatar answered Sep 17 '22 20:09

Matej