Learn Labs
PromQL

Selectors & Vectors

Instant vectors, range vectors, matchers, and staleness

PromQL is a functional language: every expression evaluates to a value, and you build bigger expressions by wrapping smaller ones. There are only four value types, and two of them do almost all the work.

TypeWhat it isExample
Instant vectorA set of series, each with one sample at the evaluation timehttp_requests_total
Range vectorA set of series, each with all samples in a time windowhttp_requests_total[5m]
ScalarA single number0.005, time()
StringRarely used"hello"

Graphs can only draw instant vectors. Range vectors are inputs to functions like rate() that turn them back into instant vectors.

Instant vector selectors

http_requests_totalevery series with this namehttp_requests_total{route="/api/orders"}= exact matchhttp_requests_total{status!="200"}!= not equalhttp_requests_total{status=~"5.."}=~ regex match (fully anchored)http_requests_total{route!~"/healthz|other"}!~ regex not matchhttp_requests_total{job="demo-app", status=~"4..|5.."}several matchers are ANDed{job="demo-app"}any metric name, one job{__name__=~"http_.*"}select by name pattern

Regexes are fully anchored: status=~"5" matches only the string 5, not 500. Use 5.. or 5.*.

How "instant" works: lookback

A query is evaluated at a specific time t. Scrapes don't happen at exactly t, so for each series Prometheus takes the most recent sample at or before t, looking back at most 5 minutes (the lookback delta). If there's no sample in that window, or the newest one is a stale marker, the series is absent from the result.

A range query (what a graph does) is just an instant query repeated at every step across the time range. A 1-hour graph at 15s step runs 240 instant evaluations.

Range vector selectors

Add a duration in brackets to get every raw sample in the window ending at t:

http_requests_total{route="/api/orders"}[1m]

# result (one series, 12 samples at a 5s scrape interval):
http_requests_total{...route="/api/orders",status="200"}
18233 @1791783000
18291 @1791783005
...
18902 @1791783055

Durations: ms, s, m, h, d, w, y, and combinations like 1h30m. The Prometheus UI's Table tab can show a range vector; the Graph tab can't, because there's no single value per time step to draw.

Functions that take range vectors

Range vectors feed two families of functions:

Counter functions, covered next in Rates & Counters:

rate(http_requests_total[5m])
increase(http_requests_total[1h])

_over_time functions, which aggregate each series over time (use them on gauges):

avg_over_time(http_requests_in_flight[10m])mean over the windowmax_over_time(http_requests_in_flight[10m])peakmin_over_time(up[1h])was it ever down in the last hour?quantile_over_time(0.95, http_requests_in_flight[1h])p95 of a gauge over timecount_over_time(up[1h])how many scrapes happenedlast_over_time(nightly_backup_rows[1d])latest value, even if older than 5mchanges(app_build_info[1d])how many times did the value change?

Literals and time

time()                                  # current evaluation time, Unix seconds
time() - process_start_time_seconds     # uptime of each process
vector(1)                               # turn a scalar into a one-series vector
scalar(sum(up))                         # turn a single-series vector into a scalar

Lab

Run each of these in the Prometheus UI and predict the number of result series before pressing Execute:

http_requests_total{job="demo-app"}
http_requests_total{job="demo-app", status=~"5.."}
http_requests_total{job="demo-app", route!="other"}
{job="demo-app", __name__=~".*_bucket"}
up{job=~"blackbox.*"}
count_over_time(up{job="demo-app"}[1m])

The last one should be 12: one sample every 5 seconds for 60 seconds. If it isn't, check the scrape_interval for that job in config/prometheus.yml.

On this page