Summary from

  • Understanding Prometheus Range Vectors
  • The Anatomy of a PromQL Query

  • What’s a Vector?
    • Since Prometheus is a timeseries database, all data is in the context of some timestamp. The series that maps a timestamp to recorded data is called a timeseries
    • a set of related timeseries is called a vector
    • Ex.
      • http_requests_total is a vector representing the total number of http requests received by a service
      • http_requests_total{code="200"} http_requests_total refers to the entire set of timeseries that are named that. And by appending a {code="200"}, we’re selecting a subset.
  • Types of Vectors
    • Instant vector - a set of timeseries where every timestamp maps to a single data point at that “instant”
      • Imagine evaluating the expression http_requests_total at a given timestamp. http_requests_total is an instant vector selector that selects the latest sample for any time series with the metric name http_requests_total. More specifically, "latest" means "at most 5 minutes old and not stale", relative to the evaluation timestamp. So this selector will only yield a result for series that have a sample at most 5 minutes prior to the evaluation timestamp, and where the last sample before the evaluation timestamp is not a stale marker (an explicit way of marking a series as terminating at a certain time in the Prometheus TSDB).
    • Range vector - a set of timeseries where every timestamp maps to a “range” of data points, recorded some duration into the past.
      • Range vector is mostly used for graphs, where you want to show a PromQL expression over a given time range. A range query works exactly like many completely independent instant queries that are evaluated at subsequent time steps over a given range of time. Of course, this is highly optimized under the hood and Prometheus doesn't actually run many independent instant queries in this case.
  • Differences
    • Instant vectors can be charted; Range vectors cannot. This is because charting something involves displaying a data point on the y-axis for every timestamp on the x-axis. Instant vectors have a single value for every timestamp, while range vectors have many of them. For the purpose of charting a metric, it is undefined1 how to show multiple data points for a single timestamp in a timeseries.
    • Instant vectors can be compared and have arithmetic performed on them; Range vectors cannot. This is also due to the way comparison and arithmetic operators are defined. For every timestamp, if we have multiple values, we don’t know how to add1 or compare them to another timeseries of a similar nature.
    • Range Vectors for counters. We take the instant vector and append our duration [15m]. This part is called the range selector and it transforms the instant vector into a range vector. We then use a function like increase which effectively subtracts the data point at the start of the range from the one at the end. increase(http_requests_total{code="200",handler="/api/v1/query"}[15m]) represent it is the increase in the total number of requests over the past fifteen minutes
Answer from zangw on Stack Overflow
🌐
Satyanash
satyanash.net › software › 2021 › 01 › 04 › understanding-prometheus-range-vectors.html
Understanding Prometheus Range Vectors - Satyajeet Kanetkar
January 4, 2021 - These cannot exist without a specified duration called the “range”, which is used to build the list of values for every timestamp. In the below example, note the list of values accompanied by a timestamp, up to 30s into the past from 1608481001.
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › basics
Querying basics | Prometheus
For example, the expression http_requests_total is equivalent to {__name__="http_requests_total"}. Matchers other than = (!=, =~, !~) may also be used. The following expression selects all metrics that have a name starting with job:: ... The metric name must not be one of the keywords bool, ...
Discussions

Generating range vectors from return values in Prometheus queries - Stack Overflow
Warning: These subqueries are expensive, i.e. create very high load on Prometheus. Use recording-rules when you use these queries regularly (in alerts, etc.). ... It returns a range-vector. In the example above, Prometheus runs rate() (= instant_query) 30 times (the first from 5 minutes ago ... More on stackoverflow.com
🌐 stackoverflow.com
prometheus - Understanding range vector selectors - Stack Overflow
From reading https://prometheus.io/docs/prometheus/latest/querying/basics/ a 'Range Vector Selectors' are defined as : Range vector literals work like instant vector literals, except that they select a range of samples back from the current instant. Syntactically, a time duration is appended in square brackets ([]) at the end of a vector selector to specify how far back in time values should be fetched for each resulting range vector element. In this example... More on stackoverflow.com
🌐 stackoverflow.com
Instant vectors to ranged vectors
Assuming you are trying to use something like a rate function. You can use a subquery for this situation; rate((some_metric*10)[1h:]) Docs: https://prometheus.io/docs/prometheus/latest/querying/basics/#subquery More on reddit.com
🌐 r/PrometheusMonitoring
1
3
March 5, 2022
[Prometheus] metrics for succeeded/failed jobs in time range
Do you mean something like this? count by (job_name) ( rate(kube_job_status_succeeded[120m]) ) More on reddit.com
🌐 r/kubernetes
2
0
April 16, 2021
Top answer
1 of 10
42

Summary from

  • Understanding Prometheus Range Vectors
  • The Anatomy of a PromQL Query

  • What’s a Vector?
    • Since Prometheus is a timeseries database, all data is in the context of some timestamp. The series that maps a timestamp to recorded data is called a timeseries
    • a set of related timeseries is called a vector
    • Ex.
      • http_requests_total is a vector representing the total number of http requests received by a service
      • http_requests_total{code="200"} http_requests_total refers to the entire set of timeseries that are named that. And by appending a {code="200"}, we’re selecting a subset.
  • Types of Vectors
    • Instant vector - a set of timeseries where every timestamp maps to a single data point at that “instant”
      • Imagine evaluating the expression http_requests_total at a given timestamp. http_requests_total is an instant vector selector that selects the latest sample for any time series with the metric name http_requests_total. More specifically, "latest" means "at most 5 minutes old and not stale", relative to the evaluation timestamp. So this selector will only yield a result for series that have a sample at most 5 minutes prior to the evaluation timestamp, and where the last sample before the evaluation timestamp is not a stale marker (an explicit way of marking a series as terminating at a certain time in the Prometheus TSDB).
    • Range vector - a set of timeseries where every timestamp maps to a “range” of data points, recorded some duration into the past.
      • Range vector is mostly used for graphs, where you want to show a PromQL expression over a given time range. A range query works exactly like many completely independent instant queries that are evaluated at subsequent time steps over a given range of time. Of course, this is highly optimized under the hood and Prometheus doesn't actually run many independent instant queries in this case.
  • Differences
    • Instant vectors can be charted; Range vectors cannot. This is because charting something involves displaying a data point on the y-axis for every timestamp on the x-axis. Instant vectors have a single value for every timestamp, while range vectors have many of them. For the purpose of charting a metric, it is undefined1 how to show multiple data points for a single timestamp in a timeseries.
    • Instant vectors can be compared and have arithmetic performed on them; Range vectors cannot. This is also due to the way comparison and arithmetic operators are defined. For every timestamp, if we have multiple values, we don’t know how to add1 or compare them to another timeseries of a similar nature.
    • Range Vectors for counters. We take the instant vector and append our duration [15m]. This part is called the range selector and it transforms the instant vector into a range vector. We then use a function like increase which effectively subtracts the data point at the start of the range from the one at the end. increase(http_requests_total{code="200",handler="/api/v1/query"}[15m]) represent it is the increase in the total number of requests over the past fifteen minutes
2 of 10
24

VictoriaMetrics author here. This is Prometheus-like monitoring system, which supports PromQL-like query language - MetricsQL.

The instant vector and range vector are indeed confusing terms in Prometheus. That's why these terms are avoided in VictoriaMetrics docs. Prometheus query language - PromQL - provides various functions, which can be divided into two groups:

  • Functions, which accept only instant vector. Such functions can be split into the following subgroups:
    • transform functions, which apply various transformations individually per each input time series. For example, abs()
    • label manipulation functions, which modify labels and metric names for the input time series. For example, label_replace()
    • aggregate functions, which aggregate multiple input time series into specified groups of output time series. For example, sum(). Fun fact is that aggregate functions are named aggregation operators in Prometheus - see these docs.
  • Functions, which accept only range vector. VictoriaMetrics names such functions as rollup functions, since they calculate the result based on input time series samples over the given lookbehind window specified in square brackets (aka sliding window). For example, rate(http_requests_total[5m]) calculates the average per-second increase rate for http_requests_total time series over the last 5 minutes.

From user's perspective the only difference between instant vector and range vector is that range vector is constructed from the instant vector by adding a lookbehind window in square brackets. For example, http_requests_total is an instant vector, while http_requests_total[5m] is a range vector. I'd say that the range vector syntax is just a syntactic sugar for rollup functions in PromQL. E.g. rate(m[d]) could be written as rate(m, d), e.g. the lookbehind window d could be passed as a separate argument to rollup functions.

🌐
SigNoz
signoz.io › guides › how to create range vectors in prometheus queries
How to Create Range Vectors in Prometheus Queries | SigNoz
November 20, 2024 - For example: http_requests_total[5m]: Returns the values of HTTP requests collected over the past 5 minutes. These differences can help in determining whether you need single-point data (instant) or need to evaluate a trend over time (range).
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
The increase is extrapolated to cover the full time range as specified in the range vector selector, so that it is possible to get a non-integer result even if a counter increases only by integer increments. The following example expression returns the number of HTTP requests as measured over the last 5 minutes, per time series in the range vector:
🌐
Zabbix
sbcode.net › prometheus › example-queries
PromQL Example Queries - Prometheus Tutorials
Examples of scalars include -1, ... a range of data points over time for each time series. Return a whole range of scrape_duration_seconds (in this case 5 minutes) for the same vector, making it a range vector....
Find elsewhere
🌐
FOSS TechNix
fosstechnix.com › home › vectors in prometheus with examples
Vectors in Prometheus with Examples
February 18, 2024 - PromQL functions like count(), min(), max(), etc., can be applied to instant vectors for aggregation. Examples: http_requests_total, up. prometheus_http_requests_total: Shows the total number of HTTP requests received by each endpoint at the moment.
Top answer
1 of 1
6

The range vector selector is just an ordinary time series selector (which is confusingly named instant vector selector) with the added lookbehind window in square brackets.

An ordinary time series selector (aka instant vector selector) selects time series matching the given filter. For example, http_requests_total{path=~"/foo/bar|/baz"} selects time series with the name http_requests_total and the path label containing either /foo/bar or /baz values.

The corresponding range vector selector with the one hour lookbehind window looks like the following http_requests_total{path=~"/foo/bar|baz"}[1h].

The range vector selector can be used in the following places:

  • It can be passed to /api/v1/query. In this case the API returns all the raw samples for matching time series on the interval (time-d ... time], where time is the query arg passed to /api/v1/query, while d is the specified lookbehind window in square brackets of range vector selector. See this article for details.

  • It can be passed to e.g. rollup functions. These functions perform calculations over raw samples on the given lookbehind window in square brackets. The calculations are performed independently per each matching time series and per each requested point on the graph. Prometheus datasource in Grafana sends requests to /api/v1/query_range. This API accepts start, end and step query args and calculates N=1+(end-start)/step points per each matching time series at timestamps start, start+step, start+2*step, ..., start+(N-1)*step.

Let's look how rate(m[d]) is calculated on the start ... end time range with the given step:

  • Prometheus selects all the time series matching m on the given time range (start-d .. end]. Note that the time range starts from start-d instead of start, where d is the provided lookbehind window in square brackets.

  • Then Prometheus calculates the average per-second increase rate over the given lookbehind window d individually per each matching time series per each requested point on the graph.

See also this answer.

🌐
PagerTree
pagertree.com › learn › prometheus › promeql › series selection
Series Selection | PagerTree
You can change any instant vector selector into a range vector selector by appending a duration specifier [<number><unit>] . For example, [5m] for a 5-minute range. ... The following example would select all the metrics with the name ...
🌐
Medium
medium.com › @ahmed.s.farag96 › decoding-promql-unraveling-range-vectors-and-instant-vectors-in-prometheus-c1390f650e5c
Decoding PromQL: Unraveling Range Vectors and Instant Vectors in Prometheus | by Ahmed Saleh | Medium
November 25, 2023 - It’s short for Promethues Querying language and in simple terms, it’s the main way to query metrics in Prometheus. ... Let’s understand the difference between Instant vector and Range vector using the above diagram.
🌐
SigNoz
signoz.io › guides › what is the difference between prometheus vectors - instant vs range explained
What is the Difference Between Prometheus Vectors - Instant vs Range Explained | SigNoz
October 14, 2024 - Prometheus organizes its time series data into two primary types of vectors: Instant Vectors: Represent data at a specific moment, capturing the latest value of each time series. Range Vectors: Represent data over a specified time range, allowing you to analyze changes and trends over time.
🌐
VictoriaMetrics
victoriametrics.com › blog › prometheus monitoring: instant queries and range queries explained
Prometheus Monitoring: Instant Queries and Range Queries Explained
February 21, 2025 - Prometheus expects one sample per timeseries at each evaluation step. That’s how it builds a continuous timeseries for charting. But this expression evaluates to a range vector, which returns multiple samples for each step, which doesn’t fit the expected format—so the system refuses to process it.
🌐
Petermalmgren
petermalmgren.com › prometheus-101
PromQL and Prometheus Operator - Peter Malmgren
July 8, 2020 - For example, if we’re scraping every 30s and we specify a range vector selector of 5 minutes (300 seconds), then we can get the estimated number of data points in the range vector by dividing 300 seconds / 30 (scrapes/second), or ~10 scrapes. One interesting thing about Prometheus counters is that they always trend upwards towards infinity because they are, by definition, an ever-increasing number.
🌐
w3tutorials
w3tutorials.net › blog › generating-range-vectors-from-return-values-in-prometheus-queries
How to Generate Range Vectors from Prometheus rate() Output: Convert Counter Metrics to Gauge for Request Rate Deviation Alerts with deriv() — w3tutorials.net
It calculates the average rate of increase of a counter over a specified time range and handles counter resets (e.g., after service restarts). Input: A range vector of a counter metric (e.g., http_requests_total[5m]).
🌐
Chronosphere
chronosphere.io › home › understanding the prometheus query language engine and its quirks
Understanding the Prometheus Query Language engine and its quirks | Chronosphere
June 26, 2024 - Range vector selectors are denoted by metric[range] syntax. They select all data points in the specified range and apply a mandatory function on them which produces a single data point. Probably the most popular example is rate(some_counter[5m]).
🌐
Rusche
rusche.me › blog › grafana-prometheus-use-range-vector
Why you should use Prometheus range vectors in your Grafana panels | Dirk Rusche
January 15, 2023 - Consider the following simplified example to visualize the problem: The black line is the real data saved in Prometheus. The red dots, which are (more or less) spread equally (excuse me my bad visualizing skills 😅), are the data points retrieved by Grafana. Your view in Grafana would look like that: which is simply not showing the peaks of the original data. Obviously, the issue gets bigger if you’re looking at long intervals or the maximum data points are only a few. The solution to that issue is a mix of using range vector selectors and aggregation over time.
🌐
Robust Perception
robustperception.io › composing-range-vector-functions-in-promql
Composing range vector functions in PromQL – Robust Perception | Prometheus Monitoring Experts
December 5, 2016 - You can add the path of a file to read rules from to your prometheus.yml: ... instance:my_counter:rate5m = rate(my_counter_total{job="myjob"}[5m]) # You can use this new metric now in rules, alerts or graphs. instance:my_counter:predict_linear1d_1h_rate5m = predict_linear(instance:my_count...
🌐
Logz.io
logz.io › home › blog › how to › an intro to promql: basic concepts & examples
An Intro to PromQL: Basic Concepts & Examples | Logz.io
September 2, 2023 - PromQL, short for Prometheus Querying Language, is the main way to query metrics within Prometheus. You can display an expression’s return either as a graph or export it using the HTTP API. PromQL uses three data types: scalars, range vectors, and instant vectors.