Skip to content

Time Series Selectors

  • Pick a selection from a time series

Label matching operators

  • =: Select labels that are exactly equal to the provided string.
  • !=: Select labels that are not equal to the provided string.
  • =~: Select labels that regex-match the provided string. env=~"foo" is treated as env=~"^foo$".
  • !~: Select labels that do not regex-match the provided string.
# all the time series
http_requests_total

# filter the time series
http_requests_total{method="GET", status!="200", service="checkout"}

# filter with regex
http_requests_total{environment=~"staging|testing|development"} # apply "or" logic
http_requests_total{environment=~"$ENVS"} # from list variable
http_requests_total{status!~"4.."}

# pick any time series whose name matches the regex (metric name is just an ordinary label with a special name)
{__name__=~"http_requests_total.*"}
{__name__=~"node_network_(receive|transmit)_bytes_total"}

# lists all time series names that have a given label
group({service="my-service"}) by (__name__)

# Also work for range vectors (selects a range of samples)
http_requests_total{job="prometheus"}[5m]

Offset modifier

  • Changes the time offset for an instant
# request with the instant time past 1 week
http_requests_total{method="GET"} offset 1w
http_requests_total{method="GET"} offset 7d

# on a range vector
rate(http_requests_total{method="GET"}[5m] offset 1w)

@ modifier

  • Specify the instant time
http_requests_total @ 1609746000
sum(http_requests_total{method="GET"} @ 1609746000)

# offset after @
http_requests_total @ 1609746000 offset 5m

# offset before @
http_requests_total offset 5m @ 1609746000