PCA (Prometheus Certified Associate) sample exam question with answer 208
Question:
Let http_requests_total be a counter metric representing the number of HTTP requests a server has handled. Further, let it be labeled by status_code representing the HTTP status code of handled requests (200, 300, 400, etc).
Which of the following queries yields the current total number of server errors (500-599) specified by the metric?
- http_requests_total{status_code=~`5\d\d`}
- sum(http_requests_total{status_code=~"5xx"})
- http_requests_total{status_code=~"5xx"}
- sum(http_requests_total{status_code=~"5\\d{2}"})
Answer:
D - correct one. Note that the \d escape sequence itself must be escaped when working in single or double quotes as opposed to backticks which do not require extra escaping
A - this query does not aggregate (sum) to get a singular total of requests with a 500
B, C - is incorrect as x is not a valid regular expression to match a digit. For that, \d must be used