Skip to content

Promql

Snippets

Generating range vectors from return values in Prometheus queries

Use the subquery-syntax

Warning: These subqueries are expensive, i.e. create very high load on Prometheus. Use recording-rules when you use these queries regularly.

Subquery syntax

<instant_query>[<range>:<resolution>]

  • instant_query: A PromQL-function which returns an instant-vector).
  • range: Offset (back in time) to start the first subquery.
  • resolution: The size of each of the subqueries.

It returns a range-vector.

For example:

deriv(rate(varnish_main_client_req[2m])[5m:10s])

In the example above, Prometheus runs rate() (= instant_query) 30 times (the first from 5 minutes ago to -4:50, ..., the last -0:10 to now). The resulting range-vector is input to the deriv() function.


Last update: 2022-11-25