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
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › basics
Querying basics | Prometheus
In Prometheus's expression language, ... for each time series, all sharing the same timestamp · Range vector - a set of time series containing a range of data points over time for each time series...
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.

Discussions

Generating range vectors from return values in Prometheus queries - Stack Overflow
I have a metric varnish_main_client_req of type counter and I want to set up an alert that triggers if the rate of requests drops/raises by a certain amount in a given time (e.g. "Amount of re... 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 sel... 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
promql - Instant vector operations on prometheus range vectors - Stack Overflow
Is there any way to perform an instant vector operation on a range vector? For instance, if we have count_containers and we want to count the fraction of the time where we have at least one, we mig... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Satyanash
satyanash.net › software › 2021 › 01 › 04 › understanding-prometheus-range-vectors.html
Understanding Prometheus Range Vectors - Satyajeet Kanetkar
January 4, 2021 - If a counter value drop below a previous recorded value, range vector functions like rate and increase will assume that the target restarted and add the entire value to the existing one it knows.
🌐
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 ... 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 - 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.
🌐
SigNoz
signoz.io › guides › how to create range vectors in prometheus queries
How to Create Range Vectors in Prometheus Queries | SigNoz
November 20, 2024 - A range vector represents a sequence of data points over a given period, enabling Prometheus to evaluate trends or patterns across intervals. Unlike instant vectors, which represent a single data point at a specific time, range vectors capture ...
Find elsewhere
🌐
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.
🌐
GitHub
github.com › alphagov › prometheus-workshop › blob › master › 04-instant-and-range-vectors.md
prometheus-workshop/04-instant-and-range-vectors.md at master · alphagov/prometheus-workshop
Instant vector - a set of time series containing a single sample for each time series, all sharing the same timestamp · Range vector - a set of time series containing a range of data points over time for each time series
Author: alphagov
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
Histogram samples in the input vector are ignored silently. delta(v range-vector) calculates the difference between the first and last value of each time series element in a range vector v, returning an instant vector with the given deltas and equivalent labels.
🌐
FOSS TechNix
fosstechnix.com › home › vectors in prometheus with examples
Vectors in Prometheus with Examples
February 18, 2024 - Range Vector in Prometheus Represent a set of time series with a range of data points over time for each series.
🌐
Robust Perception
robustperception.io › composing-range-vector-functions-in-promql
Composing range vector functions in PromQL – Robust Perception | Prometheus Monitoring Experts
December 5, 2016 - There are no functions that take a range vector and return a range vector, nor is there a way to do any form of subquery (prior to Prometheus 2.7.0). Even with support for subqueries, you wouldn't want to use them regularly as they'd be expensive.
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
So this selector will only yield ... TSDB). ... Range vector - a set of time series in which every timestamp maps to a “range” of data points recorded some duration into the past....
🌐
YouTube
youtube.com › devops hint
Vectors in Prometheus with Examples | Difference between Instant and Range Vector in Prometheus - YouTube
In this video, we are going to cover Vectors in Prometheus with Examples | What are vectors in Prometheus | Instant and Range vectors in Prometheus with exam...
Published: February 18, 2024
Views: 430
🌐
Webscale
webscale.com › home › blog › prometheus querying – breaking down promql
PromQL Querying: group_left, Joins, and Working Examples
June 8, 2026 - If each series only has a single value for each timestamp, as in the above example, the collection of series returned from a query is called an instant-vector. If each series has multiple values, it is referred to as a range-vector.
🌐
Grafana
grafana.com › blog › promql-vector-matching-what-it-is-and-how-it-affects-your-prometheus-queries
PromQL vector matching: what it is and how it affects your Prometheus queries | Grafana Labs
December 14, 2024 - In Prometheus, almost every query returns a vector, which is a collection of time series data points. These can either be an instant vector or a range vector.
🌐
Satyanash
satyanash.net › software › 2021 › 06 › 09 › charting-range-vectors-prometheus.html
Charting Range Vectors in Prometheus - Satyajeet Kanetkar
June 9, 2021 - Since this is an Instant Query, ... makes use of Grafana’s extensive control knobs. The built-in Prometheus UI does not seem to be designed to chart a Range Vector....
🌐
Reddit
reddit.com › r/prometheusmonitoring › instant vectors to ranged vectors
r/PrometheusMonitoring on Reddit: Instant vectors to ranged vectors
March 5, 2022 -

Why doesn’t ”(some_metric*10)[1h]” work? When i try it i get error: ”ranges only allowed for vector selectors”.

Wouldnt a instant vector and a scalar together return another instant vector that can be turned into a ranged vector?

Im very very stuck pls help

Top answer
1 of 2
1

Is there any way to perform an instant vector operation on a range vector?

No. Prometheus doesn't allow anything like this.

But you can apply range selector over something other than vector selector using subquery syntax. So in your example it would be something like.

avg(avg_over_time((count_containers > 0)[1h:15s]))

Notice that in this case you must place : in the range selector to indicate usage of subquery.

And for this example I used resolution 15s, to indicate that result of the query should be calculated for each 15 seconds window. But you might want to adjust this to your needs, depending on needed precision, scrape interval, etc. Also, resolution can be omitted (while preserving :, like [1h:]): in that case value of evaluation_interval will be used.


we want to count the fraction of the time where we have at least one, we might try to do:

Your attempt of the query, even if it were supported, would not produced what you wanted. Rather it would calculate average number of containers when number of containers was positive.

To calculate percentage of the time when number of containers was positive use following

avg(avg_over_time( (count_containers > bool 0)[1h:15s] ))

Expression count_containers > bool 0 will return 1 if number of containers is positive, and 0 otherwise.

2 of 2
1

If you want calculating the share of time when count_containers was positive during the last hour, it is better to use the following PromQL query:

sum(sum_over_time((count_containers >bool 0)[1h:15s]))
  /
sum(count_over_time(count_containers[1h:15s]))

This query uses the following PromQL features:

  • subquery
  • > operator with bool modifier
  • sum_over_time and count_over_time rollup functions
  • sum aggregate function
  • / binary operator.

Note that the avg(avg_over_time(...)) query may return unexpected results, since average of averages may not equal to the average.

P.S. the query above assumes that the interval between raw samples of a single time series equals to 15 seconds - see 15s in square brackets after the colon in the query above. This interval is also known as scrape_interval in Prometheus ecosystem. If your data has different scrape interval, then the value in square brackets should be adjusted in the query above. Otherwise query results will be incorrect.

P.P.S. The query can be simplified to the following one with share_gt_over_time function in MetricsQL - PromQL-like query language I work on:

share_gt_over_time(count_containers[1h], 0)