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

Question:
Which of the following PromQL expressions will calculate the average CPU usage for a server named myserver over the last 5 minutes?

  1. avg_over_time(cpu_usage{instance="myserver"}[5m])
  2. avg(cpu_usage{instance="myserver"})[5m]
  3. avg_over_time(cpu_usage{instance="myserver"}[5m]) by (instance)
  4. sum_over_time(cpu_usage{instance="myserver"}[5m])/count_over_time(cpu_usage{instance="myserver"}[5m])
Answer:
A - The avg_over_time function will calculate the average value of the cpu_usage metric over the last 5 minutes.
The instance="myserver" selector will limit the query to only data from the myserver instance.
Option B is incorrect because it uses the avg function, which will calculate the average across all instances, rather than just for myserver.
Option C is incorrect because it includes a by clause, which will group the data by instance, which is not necessary in this case.
Option D is incorrect because it uses the sum_over_time and count_over_time functions, which will calculate the sum and count of the data over time, but will not give an accurate average value