'Prometheus instant vector vs range vector


There's something I still dont understand about instant vector and range vectors

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

And I can only graph an instant vector.
I get instant vector when I write in the expression: my_metric_name and I see the value of the metric with no timestamp. How then can it be graphed? if it has only one value now. Range vector seems more logical as it has values per timestamp (writing my_metric_name[5m])

Can u explain to me then what I dont understand here about how these 2 vectors look/work?

Thank you!



Solution 1:[1]

You need to get familiar with two other related terms:

  • Instant query: when you query Prometheus for result of an expression on a single timestamp. e.g. for alerting.
  • Range query: when you query Prometheus for an expression with start and end timestamps. e.g. for graphing in Grafana.

So your expression can have a number of instant and range vectors in it, and be sent to Prometheus as an instant or range query.

Solution 2:[2]

  • I see the value of the metric with no timestamp : to answer this first, a time stamp is not shown in the results table, since we have the "Evaluation time" field already present Image for reference
  • Range vector seems more logical as it has values per timestamp : range vectors works between a range of 2 timestamps, so when you apply the [5m] to your metric, it take now-5m of the range and displays the results in that time frame, and since there maybe more than 1 results in that time frame the timestamp is shown.

This video helped me understand this very same question, hope it helps you too.

https://training.robustperception.io/courses/204997/lectures/3156025

Solution 3:[3]

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:
  • Functions, which accept only range vector. VictoriaMetrics names such functions as rollup functions, since they calculate the result based on input time series samples on 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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MaDa
Solution 2 Jehan Bhathena
Solution 3 valyala