PCA (Prometheus Certified Associate) sample exam question with answer 604

Question:
Which of the following PromQL expressions can be used to calculate the average value of a metric over a specified time range, grouped by a label?

  1. sum_over_time(metric_name[5m]) by (label)
  2. avg(metric_name[5m]) by (label)
  3. quantile(0.5, metric_name[5m]) by (label)
  4. avg_over_time(metric_name[5m]) by (label)
Answer:
D - is the correct answer. The avg_over_time function calculates the average value of a metric over a specified time range, similar to the avg function. However, avg_over_time operates on a range of time intervals rather than a fixed interval. The by clause groups the metric by the specified label. Therefore, avg_over_time(metric_name[5m]) by (label) calculates the average value of the metric over the past 5 minutes, grouped by the label label