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

Question:
Which of the following PromQL expressions can be used to calculate the number of times a metric exceeds a certain threshold over a specified time range?

  1. count_over_time(metric_name > threshold[5m])
  2. count(metric_name > threshold) by (instance)
  3. sum_over_time(metric_name > threshold[5m])
  4. sum(rate(metric_name > threshold[5m]))
Answer:
A - is the correct answer. The count_over_time function calculates the number of times a metric is non-zero over a specified time range. In this case, the expression metric_name > threshold[5m] evaluates to a binary vector that is 1 when the metric value exceeds the threshold and 0 otherwise. The count_over_time function counts the number of 1's in the vector over the past 5 minutes