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
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 › 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.
🌐
Satyanash
satyanash.net › software › 2021 › 01 › 04 › understanding-prometheus-range-vectors.html
Understanding Prometheus Range Vectors - Satyajeet Kanetkar
January 4, 2021 - Prometheus further defines two types of vectors, depending on the what the timestamps map to: Instant vector - a set of timeseries where every timestamp maps to a single data point at that “instant”. We can see the single value recorded ...
🌐
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 - Decoding PromQL: Unraveling Range Vectors and Instant Vectors in Prometheus The difference between instant and range vectors isn’t always straightforward to understand in PromQL. Many people …
🌐
FreeVector
freevector.com › vector › instant
Instant Vector Art & Graphics | freevector.com
Download Free Instant Vectors and other types of instant graphics and clipart at FreeVector.com!
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
For each input time series, changes(v range-vector) returns the number of times its value has changed within the provided time range as an instant vector. A float sample followed by a histogram sample, or vice versa, counts as a change.
Find elsewhere
🌐
Vecteezy
vecteezy.com › free-vector › instant
Instant Vector Art, Icons, and Graphics for Free Download
November 11, 2016 - Browse 28,906 incredible Instant vectors, icons, clipart graphics, and backgrounds for royalty-free download from the creative contributors at Vecteezy!
🌐
VectorStock
vectorstock.com › royalty-free-vectors › instant-vectors
Instant Vector Images (over 20,000)
The best selection of Royalty Free Instant Vector Art, Graphics and Stock Illustrations. Download 20,000+ Royalty Free Instant Vector Images.
🌐
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

🌐
Promlabs
promlabs.com › blog › 2020 › 07 › 02 › selecting-data-in-promql
PromLabs | Blog - Selecting Data in PromQL
July 2, 2020 - So some kind of middle ground is needed. To select latest samples that are neither too outdated, nor require super fast scrape intervals or even grid-aligned sample timestamps, instant vector selectors look back a maximum of 5 minutes relative to the evaluation timestamp.
🌐
Freepik
freepik.com › vectors › instant
Instant Vectors - Download Free High-Quality Vectors from Freepik | Freepik
Download the most popular free Instant vectors from Freepik. Explore AI-generated vectors and stock vectors, and take your projects to the next level with high-quality assets! #freepik
🌐
Freepik
freepik.com › free-photos-vectors › instant
Instant Images - Free Download on Freepik
Find & Download Free Graphic Resources for Instant Vectors, Stock Photos & PSD files. ✓ Free for commercial use ✓ High Quality Images #freepik
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › basics
Querying basics | Prometheus
Instant vector selectors allow the selection of a set of time series and a single sample value for each at a given timestamp (point in time).
🌐
JoVE
jove.com › home › jove core › physics › average and instantaneous velocity vectors
Average and Instantaneous Velocity Vectors in Physics
The quantity that tells us how ... between the two points approaches zero. Like average velocity, instantaneous velocity is a vector with a dimension of length per time....
Published: April 30, 2023
Views: 8
🌐
PagerTree
pagertree.com › learn › prometheus › promeql › series selection
Series Selection | PagerTree
A set of related time series is called a vector. Instant Vector - a set of time series where every timestamp maps to a single data point at that “instant”.
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)
🌐
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 - Instant vectors can be queries simply by identifying the metric name. You can filter these values by referring to labels within curly brackets.
🌐
Vecteezy
vecteezy.com › free-vector › instant
Page 32 | Instant Vector Art, Icons, and Graphics for Free Download
November 29, 2024 - Browse 28,895 incredible Instant vectors, icons, clipart graphics, and backgrounds for royalty-free download from the creative contributors at Vecteezy!
🌐
Promlabs
promlabs.com › blog › 2020 › 06 › 18 › the-anatomy-of-a-promql-query
PromLabs | Blog - The Anatomy of a PromQL Query
June 18, 2020 - Let's look at one instant query example to see how its evaluation works. 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.