There's no increases there, the time series appear with the value 1. If they had increased from 0 to 1 rather than nothing to 1 then increase would show a non-zero value. I'd recommend initialising your metrics with the label values you know about.
There's no increases there, the time series appear with the value 1. If they had increased from 0 to 1 rather than nothing to 1 then increase would show a non-zero value. I'd recommend initialising your metrics with the label values you know about.
I had the same problem, you need to get the occurrences in the range of 30 days or more, but when doing this it always returns 0, even if when doing sum(http_requests_received_total{job="TodoApi"}) it returned values.
The solution is the following, as each sample of the requests occurred in the prometheus Scrap Interval, you should then use the same interval to fetch that sample. But keeping this value in your hand, for example mine has 15s would not be feasible, since when increasing the range to 1d or more days the interval increases proportionally, this logic of the proportion I still don't understand, but there is a solution to get this value automatically using $__interval it takes the exact value, in this way the increase that previously brought a non-integer value now returns. Mine worked as follows:
increase( sum(http_requests_received_total{job="TodoApi"}) [$__interval:] )
Besides using $__interval also use : it will tell prometheus to look within the time interval obtained in $__interval:
enter image description here
increase function returns null for some data points, resulting in gaps
increase(...) appears to treat discontinuity as 0-value (leading to larger than expected increase)
Why sum(increase(metric[10m])) return all 0 value?
Why does increase() return a value of 1.33 in prometheus? - Stack Overflow
I need to use the increase function, but the metric is very rare and when service restarts the counter is null for long time. The increase metric doesn’t play nicely with the null value and I can find a solution to consider null as zero.
Increase(my_counter[1h])
Works only if there are no null data points. Any other query I tried do not work like
Increase(my_metrics[1h] or vector(0))
The challenge with calculating this number is that we only have a few data points inside a time range, and they tend not to be at the exact start and end of that time range (1 minute here). What do we do about the time between the start of the time range and the first data point, similarly the last data point and the end of the range?
We do a small bit of extrapolation to smooth this out and produce the correct result in aggregate. For very slow moving counters like this it can cause artifacts.
Prometheus calculates increase(foo_requests_total[1m]) at a timestamp t in the following way:
- It selects all the raw samples per each time series with
foo_requests_totalname on the time range(t-1m ... t]. Note that samples at the timestampt-1maren't included in the selection, while samples at the timestamptare included in the selection. - It calculates the difference
dbetween the last and the first raw sample on the selected time range (Prometheus may also remove possible counter resets, but let's skip this step for the sake of clarity). - It extrapolates the calculated difference
dif the first and/or the last raw sample are located too far from the bounds of the selected time range.
The last step may result in fractional increase() values over integer counters as seen in the original question. See this issue for more details. Note also that increase() in Prometheus misses the difference between the first raw sample on the selected time range and the previous sample before the selected time range. This may result in smaller than expected increase() results.
Prometheus developers are going to fix these issues - see this design doc. In the mean time try VictoriaMetrics - its increase() function properly returns the expected integer result without any extrapolation over integer counters.