Course contentsShow
← Cloud and Infrastructure
Lesson 1964 of 2,98942. Observability - MetricsFree lesson

Range Vector Selectors

Select time ranges of metrics using duration notation for functions that operate over time windows.

Range Vector Selectors

What you'll learn: How to select time ranges of metrics in PromQL to enable calculations over sliding windows of data.

Understanding Range Vectors

In the previous lesson, you learned about instant vectors—snapshots of metric values at a single point in time. But what if you need to ask questions like "What was the average CPU usage over the last 5 minutes?" or "How many requests occurred in the past hour?"

That's where range vector selectors come in. A range vector represents multiple samples of the same time series across a specified time window. You create one by adding a duration in square brackets after your metric selector.

Duration Notation

The syntax looks like this:

metric_name{labels}[duration]

Common duration units:

  • s — seconds
  • m — minutes
  • h — hours
  • d — days
  • w — weeks

Examples

http_requests_total[5m]

Returns all samples of http_requests_total from the last 5 minutes.

node_cpu_seconds_total{mode="idle"}[1h]

Returns 1 hour of CPU idle time samples.

up[30s]

Returns 30 seconds of "up" metric data.

Why Range Vectors Matter

Range vectors are required by many PromQL functions that calculate rates, averages, or trends over time—like rate(), irate(), avg_over_time(), and increase(). Without a time window, these functions wouldn't know what data to analyze.

Analogy: Think of an instant vector as a photograph, while a range vector is a video clip—it captures movement and change over time.

Key Takeaway: Range vector selectors use [duration] notation to fetch time-series samples across a window, enabling time-based calculations and trend analysis in Prometheus.