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
Both vectors and time series may contain a mix of float samples and histogram samples. Native histograms can have different bucket layouts, but they are generally convertible to compatible versions to apply binary and aggregation operations to them. Functions acting on range vectors that are applicable to native histograms also perform such reconciliation.
🌐
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.
🌐
Promlabs
promlabs.com › blog › 2020 › 06 › 18 › the-anatomy-of-a-promql-query
PromLabs | Blog - The Anatomy of a PromQL Query
June 18, 2020 - Of course this is highly optimized under the hood and Prometheus doesn't actually run many independent instant queries in this case. ... The PromQL expression. A start time. An end time. A resolution step. After evaluating the expression at every resolution step between the start and end time, the individually evaluated time slices are stitched together into a single range vector...
🌐
Chris's Wiki
utcc.utoronto.ca › ~cks › space › blog › sysadmin › PrometheusQuerySteps
How Prometheus's query steps (aka query resolution) work
October 13, 2018 - In general, when you write a simple Prometheus PromQL query, it is evaluated at some point in time (normally the current instant, unless you use an offset modifier). This includes queries with range vector selectors; the range vector selector chooses how far back to go from the current instant.
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.

🌐
OneUptime
oneuptime.com › home › blog › how to fix 'ranges only allowed for vector selectors' errors
How to Fix 'ranges only allowed for vector selectors' Errors
December 17, 2025 - The "ranges only allowed for vector ... Apply [5m] to the base metrics, not the expression result · Use subqueries - Add a resolution step: [1h:1m] instead of [1h]...
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › examples
Query examples | Prometheus
Note that an expression resulting in a range vector cannot be graphed directly, but viewed in the tabular ("Console") view of the expression browser. Using regular expressions, you could select time series only for jobs whose name match a certain pattern, in this case, all jobs that end with server: ... Return the 5-minute rate of the http_requests_total metric for the past 30 minutes, with a resolution of 1 minute.
Find elsewhere
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)
🌐
Robust Perception
robustperception.io › composing-range-vector-functions-in-promql
Composing range vector functions in PromQL – Robust Perception | Prometheus Monitoring Experts
December 5, 2016 - If you try and do max_over_tim... 3600) in Prometheus it won't work. How can you combine these functions? There are two general types of functions in PromQL that take timeseries as input, those that take a vector and return a vector (e.g. abs, ceil, hour, label_replace), and those that take a range vector and ...
🌐
Satyanash
satyanash.net › software › 2021 › 01 › 04 › understanding-prometheus-range-vectors.html
Understanding Prometheus Range Vectors - Satyajeet Kanetkar
January 4, 2021 - Prometheus allows exactly one case where a counter value may decrease, and that is during a target restart. If a counter value drop below a previous recorded value, range vector functions like rate and increase will assume that the target restarted ...
🌐
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 - To not break existing queries when querying downsampled data, we dynamically increase the lookback duration used in the queries to 3 * downsampling resolution, giving us these values: default (raw) data – 5m (default Prometheus ...
🌐
Google Groups
groups.google.com › g › prometheus-users › c › u4scCjDWbmA
How to solve data resolution problem when using Prometheus irate() function in the Grafana?
July 30, 2021 - But if I use variable for range-vector, I will lose many data points when I monitor a long time range graph. Because irate() considers only the last two samples. Is it okay to use irate() in Grafana? Or is there any better solution? ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... However, it's slightly broken. What you'll actually get is a correct foo[...] range at large zoom, but at small zoom it won't go any smaller than foo[20s], which means it smears together three time intervals (i.e.
🌐
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 › 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 ...
🌐
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 - When working with Prometheus vectors, you may encounter several challenges: ... For instant vectors: Use default values (e.g., or operator in PromQL) to handle missing data. For range vectors: Consider using functions like absent_over_time() to detect gaps.
🌐
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
🌐
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.
🌐
Satyanash
satyanash.net › software › 2021 › 06 › 09 › charting-range-vectors-prometheus.html
Charting Range Vectors in Prometheus - Satyajeet Kanetkar
June 9, 2021 - In the previous blog post, we mentioned that Range Vectors cannot be charted.This blog post illustrates how we can work around the limitations and use Range ...
🌐
Prometheus
prometheus.io › blog › 2019 › 01 › 28 › subquery-support
Subquery Support | Prometheus
January 28, 2019 - The result of a subquery is a range vector. The Prometheus team arrived at a consensus for the syntax of subqueries at the Prometheus Dev Summit 2018 held in Munich. These are the notes of the summit on subquery support , and a brief design doc for the syntax used for implementing subquery support. <instant_query> '[' <range> ':' [ <resolution> ] ']' [ offset <duration> ]