Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PromQL avg vs avg_over_time

Tags:

promql

Over time functions are not supporting by/without syntax. Which is the mathematical difference between using avg_over_time(metric[1h]) and avg(metric[1h])? Can a over time function be replaced with a function (in this case avg) with the same results? Thanks!

like image 704
RJtokenring Avatar asked Jan 22 '26 07:01

RJtokenring


2 Answers

The avg_over_time(m[d]) function performs the following:

  • it selects all the time series with name m
  • then for every selected time series it calculates the average value across raw samples on the time range d preceding every point on the graph.

The avg(m) function performs the following:

  • it selects all the time series with name m
  • then for every selected time series it selects the last raw sample value before every point on the graph. See these docs for more details.
  • then for every point on the graph it calculates the average value across the selected values for every time series.

As you can see, avg_over_time() and avg() are quite different functions - avg_over_time() calculates distinct average values for every selected time series, while avg() calculates average values across the selected time series.

like image 151
valyala Avatar answered Jan 25 '26 08:01

valyala


Why can't you just use

avg(avg_over_time(m[d]))

instead of

sum(sum_over_time(m[d])) by (...) / sum(count_over_time(m[d])) by (...)
like image 33
eng007 Avatar answered Jan 25 '26 06:01

eng007



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!