PCA practice question 2 of 15

How can you select all the up metrics whose instance label matches the regex fe-.*?

Full set: 60 questions
Answer options
A: up{instance=regexp(fe-.*)}
B: up{instance="fe-.*"}
C: up{instance~"fe-.*"}
D: up{instance=~"fe-.*"} Correct answer
Correct Answer:
D. up{instance=~"fe-.*"}
Explanation

In Prometheus Query Language (PromQL), time series are filtered using label selectors. To filter based on a regular expression match, the =~ operator is used. The query up{instance=~"fe-."} correctly selects all time series with the metric name up where the instance label value matches the regular expression fe-.. This expression matches any instance label that starts with the string "fe-".

Why Incorrect

A. regexp() is not a valid function or operator for label matching within a PromQL selector block.
B. The = operator performs an exact string match, so it would look for a label literally named "fe-.".
C. The ~ operator is not a valid label matching operator in PromQL syntax.

References

1. Prometheus Official Documentation, "Querying Prometheus - Selectors": This document explicitly defines the label matching operators available in PromQL. It states: "=~: Select labels that regex-match the provided string." This directly supports the use of =~ for the required regular expression matching. The documentation is available at: https://prometheus.io/docs/prometheus/latest/querying/basics/#time-series-selectors (Section: Time series Selectors).

2. University of Washington, CSE 451: Introduction to Operating Systems, "Monitoring" Lecture Slides: Course materials on system monitoring often cover Prometheus. Slide 23 of the "Monitoring" lecture deck details PromQL queries and explicitly lists =~ as the operator for "matches regex". This confirms its use in an academic context. (Reference: https://courses.cs.washington.edu/courses/cse451/21au/lectures/23-monitoring.pdf, Slide 23).

Scroll to Top