21

How can I find the overall average of metrics over time interval ?

avg(metric) = overall average value but

avg_over_time(metrics[interval]) = averages value per label

avg( avg_over_time(metric[scrape interval]) ) won't be same as(when the data is not continuous and denominator value is different) avg(metric) !!!!

Given a scenario, what will be the possible way to find the overall average over a time period.

Eg: Find the average response time now and Find the average response time(over all) of all the request triggered in last one hour.

The number will be helpful to notify a performance issue with latest upgrades.

Vaisakh Rajagopal
  • 1,189
  • 1
  • 14
  • 23

1 Answers1

39

You need to calculate the average a bit more manually:

    sum(sum_over_time(metric[interval]))
/
    sum(count_over_time(metric[interval]))

Note that this is for data in a gauge, you'd need a different approach for data from a counter or summary.

brian-brazil
  • 31,678
  • 6
  • 93
  • 86
  • Thanks. Missed it. My metrics are of type Summary, sum(sum_over_time(metric_sum[interval])) / sum(sum_over_time(metric_count[interval])) !!! – Vaisakh Rajagopal Aug 15 '18 at 17:33
  • 5
    For a summary it's `sum(rate(a_sum[interval])) / sum(rate(a_count[interval]))`. See https://www.robustperception.io/common-query-patterns-in-promql – brian-brazil Aug 15 '18 at 17:38