Skip to main content
This lesson explains how to use selectors and label matchers in PromQL to filter Prometheus time series. When you request a metric by name without any labels, Prometheus returns every time series for that metric:
Example result (all time series for that metric):
To narrow results, apply label matchers inside braces after the metric name. Prometheus supports four matcher types:
The image is a guide on "Matchers" for time series metrics, outlining different types of label matchers such as exact match, negative equality matcher, and regular expression matcher.
Below are concise examples demonstrating each matcher and the expected filtered results. Equality matcher
  • Use = to select series with an exact label value. Example: get filesystem availability for node1 only.
Result (only series with instance="node1"):
Negative equality matcher
  • Use != to remove series matching a specific label value. Example: exclude tmpfs devices.
Result (series with device not equal to tmpfs):
Regular expression matcher
  • Use =~ to match label values with a regex. Example: match devices that start with /dev/sda.
Result (series with device matching /dev/sda.*):
Regular expressions are powerful but can impact performance if overused. Test and keep regex patterns as simple and specific as possible. For a regex reference, see Regular-Expressions.info.
Negative regular expression matcher
  • Use !~ to exclude series whose label values match a regex. Example: exclude mount points beginning with /boot.
Result (all series except those whose mountpoint starts with /boot):
Combining selectors
  • Combine multiple label matchers by separating them with commas inside the braces. Example: series on node1 excluding tmpfs devices.
Result (series on node1 excluding tmpfs devices):
Range vector selector
  • An instant vector returns the latest sample per series. A range vector returns the sequence of samples for each matching series over a specified duration. Use square brackets with a duration to request a range vector. Example: last 2 minutes for node_arp_entries on node1.
Sample result (a range vector contains multiple timestamped samples per series):
You can use any PromQL duration (for example 5m, 1h, 5d) depending on how far back you need data. Additional resources
Make sure label values and regex patterns are quoted correctly. Unquoted or malformed regexes can cause query errors. When in doubt, test queries in the Prometheus UI or Grafana Explore.

Watch Video