On Friday, 20 November 2020 at 02:29:12 UTC [email protected] wrote:

> *Query*:
>  1. normal query: error_counter_something{job=“monitor”, device=“dev0”, 
> serial=“xxxxxxxx”}
>  2. delta query: delta(error_counter_something{job=“monitor”, 
> device=“dev0”, serial=“xxxxxxxx”}[$__interval] > 0)
>
> *Time Range*: 2020-11-19 16:16:00 ~ 2020-11-19 16:20:00 with 15sec 
> interval
>
> *result*
>
> 16:16:15~30 raise 2 errors on device and move that error counter value 
> from 7616 to 7618,
> but the delta query shows result of 3
>
> time                             ,            delta  ,                 
> normal 
> 2020-11-19 16:16:00,                       ,                     7616
> 2020-11-19 16:16:15,                       ,                     7616
> 2020-11-19 16:16:30,                     3,                     7618
> 2020-11-19 16:16:45,                       ,                     7618
> 2020-11-19 16:17:00,                       ,                     7618
> (keep these value until end of query time range)
>
>
See https://prometheus.io/docs/prometheus/latest/querying/functions/#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. The delta is 
extrapolated to cover the full time range as specified in the range vector 
selector, so that it is possible to get a non-integer result even if the 
sample values are all integers."*

You haven't said what $__interval expands to in your query.  It must be at 
least 30 seconds, because otherwise you wouldn't have two values in your 
range vector.

So let's see what happens with 30 seconds.  The window contains two values:

[...X........X...]
   7616    7618
    <--15s-->

The difference between these is 2, and the time interval between them is 15 
seconds.  However this increase is then extrapolated to cover the whole 
window period of 30 seconds, so the value returned by delta() would be 4.

What about if $__interval was 45 seconds?  Then you'd have three values, 
the difference between the first and last is 2, the time difference is 30 
seconds extrapolated to 45 seconds, so the result would be 2 x (45/30) = 3.

If you want the actual difference between the metric now and the metric 
some time ago, you can do :

something - something offset 15s

However, both that expression and delta() will give you nonsense values if 
a counter resets, because it will jump back down towards zero and give you 
a large negative value.

Better:

(something - something offset 15s) >= 0

but it won't handle counter resets as well as rate() or increase() can.

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/f75b2007-96ed-4c66-b719-602934827cd3n%40googlegroups.com.

Reply via email to