Delta usage issues?

59 views
Skip to first unread message

li yun

unread,
Oct 13, 2020, 4:24:54 AM10/13/20
to Prometheus Users
I want to get the difference between the current time and the past 5 minutes, but I tried two methods and couldn’t get it

1. delta(isphone{name="qq",exname!~"test|test1"}[5m]) 

2. sum_over_time(isphone{name="qq",exname!~"test|test1"}[5m]) - sum_over_time(isphone{name="qq",exname!~"test|test1"}[5m])offset 5m )

If I execute sum_over_time(isphone{name="qq",exname!~"test|test1"}[5m]) directly, the data can be displayed normally, but I can’t get the difference between now and five minutes ago. Can anyone have a way? ?

Brian Candler

unread,
Oct 13, 2020, 2:28:31 PM10/13/20
to Prometheus Users
To take the difference between an instance vector as it is now and how it was 5 minutes ago:

foo - foo offset 5m

However that doesn't explain why your delta(...) expression doesn't work.  Can you show the input data, what output data you get, and what output you expected to see?

It also doesn't explain why you want to use sum_over_time(...).  What does this metric represent?

li yun

unread,
Oct 15, 2020, 10:32:29 PM10/15/20
to Brian Candler, Prometheus Users
Because my data is collected every 5 minutes, I use sum_over_time. If I don’t use it, it may not be possible to draw the graph at some points.

Brian Candler <b.ca...@pobox.com> 于2020年10月14日周三 上午2:28写道:
--
You received this message because you are subscribed to a topic in the Google Groups "Prometheus Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/prometheus-users/yS43RBTGls4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/5e457d67-6f4c-4885-b51c-5db9d7662620o%40googlegroups.com.

li yun

unread,
Oct 16, 2020, 2:36:24 AM10/16/20
to Brian Candler, Prometheus Users
My data is collected in 5 minutes, so I need to add sum_over_time, otherwise some points will be lost,I try to use sum_over_time(isphone{name="qq",exname!~"test|test1"}[5m])-sum_over_time(isphone{name="qq",exname!~"test|test1"}[5m]) offset 5m ), but this will prompt a syntax error. I haven't thought of a better way. I hope to get help. Thank you very much.

li yun <linux...@gmail.com> 于2020年10月16日周五 上午10:32写道:

Brian Candler

unread,
Oct 16, 2020, 2:37:55 AM10/16/20
to Prometheus Users
On Friday, 16 October 2020 03:32:29 UTC+1, li yun wrote:
Because my data is collected every 5 minutes, I use sum_over_time. If I don’t use it, it may not be possible to draw the graph at some points.


That doesn't make sense to me.  Prometheus will look back up to 5 minutes to find a data point anyway.

You're correct that if you sample at 5 minute intervals, and you do sum_over_time[5m], then *normally* the sum_over_time will sum exactly one data point.  If the samples aren't *exactly* 5 minutes apart then sometimes it will return zero, and sometimes it will sum two data points, both of which are silly.

Prometheus recommends a *minimum* polling time of 2 minutes, so that if one scrape is missed, the timeseries does not go scale (i.e. the last point can be found).

li yun

unread,
Oct 16, 2020, 2:54:01 AM10/16/20
to Brian Candler, Prometheus Users
In the process of capturing data, the server needs to calculate for five minutes before returning the result, so I need to collect it every 5 minutes。

Brian Candler <b.ca...@pobox.com> 于2020年10月16日周五 下午2:38写道:
--
You received this message because you are subscribed to a topic in the Google Groups "Prometheus Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/prometheus-users/yS43RBTGls4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to prometheus-use...@googlegroups.com.

Brian Candler

unread,
Oct 16, 2020, 3:05:29 AM10/16/20
to Prometheus Users
The recommended way to do this is:
- run your collection script every 5 minutes, e.g. as a cron job
- write the results to a text file which is picked up by node_exporter textfile collector

You can then scrape the data as often as you like, from as many prometheus servers as you like.

li yun

unread,
Oct 16, 2020, 8:32:01 PM10/16/20
to Brian Candler, Prometheus Users
My purpose is because there are so many indicators, I need to know that some indicators suddenly decrease, hoping to know the specific indicator name, so I use sum_over_time(isphone{name="qq",exname!~"test|test1"}[5m ])-sum_over_time(isphone{name="qq",exname!~"test|test1"}[5m])offset 5m)。

Brian Candler <b.ca...@pobox.com> 于2020年10月16日周五 下午3:05写道:
--
You received this message because you are subscribed to a topic in the Google Groups "Prometheus Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/prometheus-users/yS43RBTGls4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to prometheus-use...@googlegroups.com.

Christian Hoffmann

unread,
Oct 17, 2020, 3:24:17 AM10/17/20
to li yun, Brian Candler, Prometheus Users
On 10/17/20 2:31 AM, li yun wrote:
> sum_over_time(isphone{name="qq",exname!~"test|test1"}[5m
> ])-sum_over_time(isphone{name="qq",exname!~"test|test1"}[5m])offset 5m

Try placing the offset modifier right next to the metric name:

sum_over_time(isphone{name="qq",exname!~"test|test1"}[5m]) -
sum_over_time(isphone{name="qq",exname!~"test|test1"}[5m] offset 5m)
Reply all
Reply to author
Forward
0 new messages