Project: VictoriaMetrics (Observability and Analysis / Observability)
File: MetricsQL.da86c2db4f0b05e286b0.md

sort: 23 weight: 23 title: MetricsQL menu: docs: parent: 'victoriametrics' weight: 23 aliases: /ExtendedPromQL.html /MetricsQL.html implements MetricsQL - query language inspired by . MetricsQL is backwards-compatible with PromQL, so Grafana dashboards backed by Prometheus datasource should work the same after switching from Prometheus to VictoriaMetrics. However, there are some between these two languages. can be used for parsing MetricsQL in external apps. If you are unfamiliar with PromQL, then it is suggested reading and introduction into . The following functionality is implemented differently in MetricsQL compared to PromQL. This improves user experience: MetricsQL takes into account the last before the lookbehind window in square brackets for and functions. This allows returning the exact results users expect for `increase(metric[$interval])` queries instead of incomplete results Prometheus returns for such queries. Prometheus misses the increase between the last sample before the lookbehind window and the first sample inside the lookbehind window. MetricsQL doesn't extrapolate and function results, so it always returns the expected results. For example, it returns integer results from `increase()` over slow-changing integer counter. Prometheus in this case returns unexpected fractional results, which may significantly differ from the expected results. This addresses . See technical details about VictoriaMetrics and Prometheus calculations for and . MetricsQL returns the expected non-empty responses for function when Grafana or passes `step` values smaller than the interval between to . This addresses . See also . MetricsQL treats `scalar` type the same as `instant vector` without labels, since subtle differences between these types usually confuse users. See for details. MetricsQL removes all the `NaN` values from the output, so some queries like `(-1)^0.5` return empty results in VictoriaMetrics, while returning a series of `NaN` values in Prometheus. Note that Grafana doesn't draw any lines or dots for `NaN` values, so the end result looks the same for both VictoriaMetrics and Prometheus. MetricsQL keeps metric names after applying functions, which don't change the meaning of the original time series. For example, or leaves `foo` metric name in the result. See for details. Read more about the differences between PromQL and MetricsQL in . Other PromQL functionality should work the same in MetricsQL. if you notice discrepancies between PromQL and MetricsQL results other than mentioned above. MetricsQL implements and provides additional functionality mentioned below, which is aimed towards solving practical cases. Feel free if you think MetricsQL misses certain useful functionality. This functionality can be evaluated at or at your own . The list of MetricsQL features on top of PromQL: Graphite-compatible filters can be passed via `{__graphite__="foo..bar"}` syntax. See . VictoriaMetrics can be used as Graphite datasource in Grafana. See for details. See also function, which can be used for extracting the given groups from Graphite metric name. Lookbehind window in square brackets for may be omitted. VictoriaMetrics automatically selects the lookbehind window depending on the `step` query arg passed to and the real interval between (aka `scrape_interval`). For instance, the following query is valid in VictoriaMetrics: `rate(nodenetworkreceivebytestotal)`. It is roughly equivalent to `rate(nodenetworkreceivebytestotal[$interval])` when used in Grafana. The difference is documented in . Numeric values can contain `` delimiters for better readability. For example, `1234567890` can be used in queries instead of `1234567890`. accept multiple `or` filters. For example, `{env="prod",job="a" or env="dev",job="b"}` selects series with `{env="prod",job="a"}` or `{env="dev",job="b"}` labels. See for details. Support for `group_left()` and `group_right(*)` for copying all the labels from time series on the `one` side of . The copied label names may clash with the existing label names, so MetricsQL provides an ability to add prefix to the copied metric names via `group_left(*) prefix "..."`

For example, the following query copies all the `namespace`-related labels from `kubenamespacelabels` to `kubepodinfo` series, while adding `ns` prefix to the copied labels: `kubepodinfo * on(namespace) groupleft(*) prefix "ns" kubenamespace_labels`. Labels from the `on()` list aren't copied. accept arbitrary number of args. For example, `avg(q1, q2, q3)` would return the average values for every point across time series returned by `q1`, `q2` and `q3`. can be put anywhere in the query. For example, `sum(foo) @ end()` calculates `sum(foo)` at the `end` timestamp of the selected time range `[start ... end]`. Arbitrary subexpression can be used as . For example, `foo @ (end() - 1h)` calculates `foo` at the `end - 1 hour` timestamp on the selected time range `[start ... end]`. , lookbehind window in square brackets and `step` value for may refer to the current step aka `$interval` value from Grafana with `[Ni]` syntax. For instance, `rate(metric[10i] offset 5i)` would return per-second rate over a range covering 10 previous steps with the offset of 5 steps. may be put anywhere in the query. For instance, `sum(foo) offset 24h`. Lookbehind window in square brackets and may be fractional. For instance, `rate(nodenetworkreceivebytestotal[1.5m] offset 0.5d)`. The duration suffix is optional. The duration is in seconds if the suffix is missing. For example, `rate(m[300] offset 1800)` is equivalent to `rate(m[5m]) offset 30m`. The duration can be placed anywhere in the query. For example, `sumovertime(m[1h]) / 1h` is equivalent to `sumovertime(m[1h]) / 3600`. Numeric values can have `K`, `Ki`, `M`, `Mi`, `G`, `Gi`, `T` and `Ti` suffixes. For example, `8K` is equivalent to `8000`, while `1.2Mi` is equivalent to `1.21024*1024`. Trailing commas on all the lists are allowed - label filters, function args and with expressions. For instance, the following queries are valid: `m{foo="bar",}`, `f(a, b,)`, `WITH (x=y,) x`. This simplifies maintenance of multi-line queries. Metric names and label names may contain any unicode letter. For example `{=""}` is a value MetricsQL expression. Metric names and labels names may contain escaped chars. For example, `foo\-bar{baz\=aa="b"}` is valid expression. It returns time series with name `foo-bar` containing label `baz=aa` with value `b`. Additionally, the following escape sequences are supported: `\xXX`, where `XX` is hexadecimal representation of the escaped ascii char. `\uXXXX`, where `XXXX` is a hexadecimal representation of the escaped unicode char. Aggregate functions support optional `limit N` suffix in order to limit the number of output series. For example, `sum(x) by (y) limit 3` limits the number of output time series after the aggregation to 3. All the other time series are dropped. accepts optional third arg - `boundsLabel`. In this case it returns `lower` and `upper` bounds for the estimated percentile. See . `default` binary operator. `q1 default q2` fills gaps in `q1` with the corresponding values from `q2`. See also . `if` binary operator. `q1 if q2` removes values from `q1` for missing values from `q2`. `ifnot` binary operator. `q1 ifnot q2` removes values from `q1` for existing values from `q2`. `WITH` templates. This feature simplifies writing and managing complex queries. Go to and try it. String literals may be concatenated. This is useful with `WITH` templates: `WITH (commonPrefix="longmetricprefix") {name=commonPrefix+"suffix1"} / {name_=commonPrefix+"suffix2"}`. `keepmetricnames` modifier can be applied to all the , and . This modifier prevents from dropping metric names in function results. See . By default, metric names are dropped after applying functions or , since they may change the meaning of the original time series. This may result in `duplicate time series` error when the function is applied to multiple time series with different

This error can be fixed by applying `keepmetricnames` modifier to the function or binary operator. For example: `rate({name=~"foo|bar"}) keepmetricnames` leaves `foo` and `bar` metric names in the returned time series. `({name=~"foo|bar"} / 10) keepmetricnames` leaves `foo` and `bar` metric names in the returned time series. If you are unfamiliar with PromQL, then please read at first. MetricsQL provides the following functions: Rollup functions (aka range functions or window functions) calculate rollups over raw samples on the given lookbehind window for the . For example, `avgovertime(temperature[24h])` calculates the average temperature over raw samples for the last 24 hours. Additional details: If rollup functions are used for building graphs in Grafana, then the rollup is calculated independently per each point on the graph. For example, every point for `avgovertime(temperature[24h])` graph shows the average temperature for the last 24 hours ending at this point. The interval between points is set as `step` query arg passed by Grafana to . If the given returns multiple time series, then rollups are calculated individually per each returned series. If lookbehind window in square brackets is missing, then it is automatically set to the following value: To `step` value passed to or for all the except of and . This value is known as `$interval` in Grafana or `1i` in MetricsQL. For example, `avgovertime(temperature)` is automatically transformed to `avgovertime(temperature[1i])`. To the `max(step, scrapeinterval)`, where `scrapeinterval` is the interval between for and functions. This allows avoiding unexpected gaps on the graph when `step` is smaller than `scrape_interval`. Every in MetricsQL must be wrapped into a rollup function. Otherwise, it is automatically wrapped into . For example, `foo{bar="baz"}` is automatically converted to `default_rollup(foo{bar="baz"})` before performing the calculations. If something other than is passed to rollup function, then the inner arg is automatically converted to a . All the rollup functions accept optional `keepmetricnames` modifier. If it is set, then the function keeps metric names in results. See . See also . The list of supported rollup functions: `absentovertime(series_selector, which returns 1 if the given lookbehind window `d` doesn't contain raw samples. Otherwise, it returns an empty result. This function is supported by PromQL. See also . `aggrovertime(("rollupfunc1", "rollupfunc2", ...), series_selector, which calculates all the listed `rollup_func*` for raw samples on the given lookbehind window `d`. The calculations are performed individually per each time series returned from the given . `rollupfunc*` can contain any rollup function. For instance, `aggrovertime(("minovertime", "maxover_time", "rate"), m[d])` would calculate , and for `m[d]`. `ascentovertime(series_selector, which calculates ascent of raw sample values on the given lookbehind window `d`. The calculations are performed individually per each time series returned from the given . This function is useful for tracking height gains in GPS tracking. Metric names are stripped from the resulting rollups. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `avgovertime(series_selector, which calculates the average value over raw samples on the given lookbehind window `d` per each time series returned from the given . This function is supported by PromQL. See also . `changes(series_selector, which calculates the number of times the raw samples changed on the given lookbehind window `d` per each time series returned from the given . Unlike `changes()` in Prometheus it takes into account the change from the last sample before the given lookbehind window `d`. See for details. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. See also

`changesprometheus(seriesselector, which calculates the number of times the raw samples changed on the given lookbehind window `d` per each time series returned from the given . It doesn't take into account the change from the last sample before the given lookbehind window `d` in the same way as Prometheus does. See for details. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. See also . `counteqovertime(seriesselector, which calculates the number of raw samples on the given lookbehind window `d`, which are equal to `eq`. It is calculated independently per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also , and . `countgtovertime(seriesselector, which calculates the number of raw samples on the given lookbehind window `d`, which are bigger than `gt`. It is calculated independently per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also and . `countleovertime(seriesselector, which calculates the number of raw samples on the given lookbehind window `d`, which don't exceed `le`. It is calculated independently per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also and . `countneovertime(seriesselector, which calculates the number of raw samples on the given lookbehind window `d`, which aren't equal to `ne`. It is calculated independently per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `countovertime(series_selector, which calculates the number of raw samples on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. See also , , and . `countvaluesovertime("label", seriesselector, which counts the number of raw samples with the same value over the given lookbehind window and stores the counts in a time series with an additional `label`, which contains each initial value. The results are calculated independently per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also , and and . `decreasesovertime(series_selector, which calculates the number of raw sample value decreases over the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `defaultrollup(seriesselector, which returns the last raw sample value on the given lookbehind window `d` per each time series returned from the given . If the lookbehind window is skipped in square brackets, then it is automatically calculated as `max(step, scrape_interval)`, where `step` is the query arg value passed to or , while `scrape_interval` is the interval between for the selected time series. This allows avoiding unexpected gaps on the graph when `step` is smaller than the `scrape_interval`. `delta(series_selector, which calculates the difference between the last sample before the given lookbehind window `d` and the last sample at the given lookbehind window `d` per each time series returned from the given . The behaviour of `delta()` function in MetricsQL is slightly different to the behaviour of `delta()` function in Prometheus. See for details. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. See also and

`deltaprometheus(seriesselector, which calculates the difference between the first and the last samples at the given lookbehind window `d` per each time series returned from the given . The behaviour of `delta_prometheus()` is close to the behaviour of `delta()` function in Prometheus. See for details. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `deriv(series_selector, which calculates per-second derivative over the given lookbehind window `d` per each time series returned from the given . The derivative is calculated using linear regression. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. See also and . `derivfast(seriesselector, which calculates per-second derivative using the first and the last raw samples on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also and . `descentovertime(series_selector, which calculates descent of raw sample values on the given lookbehind window `d`. The calculations are performed individually per each time series returned from the given . This function is useful for tracking height loss in GPS tracking. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `distinctovertime(series_selector, which returns the number of distinct raw sample values on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `durationovertime(series_selector, which returns the duration in seconds when time series returned from the given were present over the given lookbehind window `d`. It is expected that intervals between adjacent samples per each series don't exceed the `max_interval`. Otherwise, such intervals are considered as gaps and aren't counted. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also and . `firstovertime(series_selector, which returns the first raw sample value on the given lookbehind window `d` per each time series returned from the given . See also and . `geomeanovertime(series_selector, which calculates over raw samples on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. `histogramovertime(series_selector, which calculates over raw samples on the given lookbehind window `d`. It is calculated individually per each time series returned from the given . The resulting histograms are useful to pass to for calculating quantiles over multiple . For example, the following query calculates median temperature by country over the last 24 hours: `histogramquantile(0.5, sum(histogramover_time(temperature[24h])) by (vmrange,country))`. `hoeffdingboundlower(phi, series_selector, which calculates lower for the given `phi` in the range `[0...1]`. See also . `hoeffdingboundupper(phi, series_selector, which calculates upper for the given `phi` in the range `[0...1]`. See also . `holtwinters(seriesselector, which calculates Holt-Winters value (aka ) for raw samples over the given lookbehind window `d` using the given smoothing factor `sf` and the given trend factor `tf`. Both `sf` and `tf` must be in the range ` returns time series of . This function is supported by PromQL. See also . `idelta(series_selector, which calculates the difference between the last two raw samples on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. See also

`ideriv(series_selector, which calculates the per-second derivative based on the last two raw samples over the given lookbehind window `d`. The derivative is calculated independently per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `increase(series_selector, which calculates the increase over the given lookbehind window `d` per each time series returned from the given . It is expected that the `series_selector` returns time series of . Unlike Prometheus, it takes into account the last sample before the given lookbehind window `d` when calculating the result. See for details. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. See also , and . `increaseprometheus(seriesselector, which calculates the increase over the given lookbehind window `d` per each time series returned from the given . It is expected that the `series_selector` returns time series of . It doesn't take into account the last sample before the given lookbehind window `d` when calculating the result in the same way as Prometheus does. See for details. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also and . `increasepure(seriesselector, which works the same as except of the following corner case - it assumes that always start from 0, while ignores the first value in a series if it is too big. `increasesovertime(series_selector, which calculates the number of raw sample value increases over the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `integrate(series_selector, which calculates the integral over raw samples on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. `irate(series_selector, which calculates the "instant" per-second increase rate over the last two raw samples on the given lookbehind window `d` per each time series returned from the given . It is expected that the `series_selector` returns time series of . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. See also and . `lag(series_selector, which returns the duration in seconds between the last sample on the given lookbehind window `d` and the timestamp of the current point. It is calculated independently per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also and . `lastovertime(series_selector, which returns the last raw sample value on the given lookbehind window `d` per each time series returned from the given . This function is supported by PromQL. See also and . `lifetime(series_selector, which returns the duration in seconds between the last and the first sample on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also and . `madovertime(series_selector, which calculates over raw samples on the given lookbehind window `d` per each time series returned from the given . See also , and . `maxovertime(series_selector, which calculates the maximum value over raw samples on the given lookbehind window `d` per each time series returned from the given . This function is supported by PromQL. See also

`medianovertime(series_selector, which calculates median value over raw samples on the given lookbehind window `d` per each time series returned from the given . See also . `minovertime(series_selector, which calculates the minimum value over raw samples on the given lookbehind window `d` per each time series returned from the given . This function is supported by PromQL. See also . `modeovertime(series_selector, which calculates ) for raw samples on the given lookbehind window `d`. It is calculated individually per each time series returned from the given . It is expected that raw sample values are discrete. `outlieriqrovertime(seriesselector, which returns the last sample on the given lookbehind window `d` if its value is either smaller than the `q25-1.5iqr` or bigger than `q75+1.5iqr` where: `iqr` is an over raw samples on the lookbehind window `d` `q25` and `q75` are 25th and 75th over raw samples on the lookbehind window `d`. The `outlieriqrover_time()` is useful for detecting anomalies in gauge values based on the previous history of values. For example, `outlieriqrovertime(memoryusagebytes[1h])` triggers when `memoryusage_bytes` suddenly goes outside the usual value range for the last hour. See also . `predictlinear(seriesselector, which calculates the value `t` seconds in the future using linear interpolation over raw samples on the given lookbehind window `d`. The predicted value is calculated individually per each time series returned from the given . This function is supported by PromQL. See also . `presentovertime(series_selector, which returns 1 if there is at least a single raw sample on the given lookbehind window `d`. Otherwise, an empty result is returned. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. `quantileovertime(phi, series_selector, which calculates `phi`-quantile over raw samples on the given lookbehind window `d` per each time series returned from the given . The `phi` value must be in the range `[0...1]`. This function is supported by PromQL. See also . `quantilesovertime("phiLabel", phi1, ..., phiN, series_selector, which calculates `phi*`-quantiles over raw samples on the given lookbehind window `d` per each time series returned from the given . The function returns individual series per each `phi` with `{phiLabel="phi"}` label. `phi*` values must be in the range `[0...1]`. See also . `rangeovertime(series_selector, which calculates value range over raw samples on the given lookbehind window `d` per each time series returned from the given . E.g. it calculates `maxovertime(seriesselector[d]) - minovertime(seriesselector[d])`. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. `rate(series_selector, which calculates the average per-second increase rate over the given lookbehind window `d` per each time series returned from the given . It is expected that the `series_selector` returns time series of . If the lookbehind window is skipped in square brackets, then it is automatically calculated as `max(step, scrape_interval)`, where `step` is the query arg value passed to or , while `scrape_interval` is the interval between for the selected time series. This allows avoiding unexpected gaps on the graph when `step` is smaller than the `scrape_interval`. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. See also and . `rateoversum(series_selector, which calculates per-second rate over the sum of raw samples on the given lookbehind window `d`. The calculations are performed individually per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. `resets(series_selector, which returns the number of resets over the given lookbehind window `d` per each time series returned from the given

It is expected that the `series_selector` returns time series of . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. `rollup(series_selector, which calculates `min`, `max` and `avg` values for raw samples on the given lookbehind window `d` and returns them in time series with `rollup="min"`, `rollup="max"` and `rollup="avg"` additional labels. These values are calculated individually per each time series returned from the given . Optional 2nd argument `"min"`, `"max"` or `"avg"` can be passed to keep only one calculation result and without adding a label. See also . `rollupcandlestick(seriesselector, which calculates `open`, `high`, `low` and `close` values (aka OHLC) over raw samples on the given lookbehind window `d` and returns them in time series with `rollup="open"`, `rollup="high"`, `rollup="low"` and `rollup="close"` additional labels. The calculations are performed individually per each time series returned from the given . This function is useful for financial applications. Optional 2nd argument `"open"`, `"high"` or `"low"` or `"close"` can be passed to keep only one calculation result and without adding a label. See also . `rollupdelta(seriesselector, which calculates differences between adjacent raw samples on the given lookbehind window `d` and returns `min`, `max` and `avg` values for the calculated differences and returns them in time series with `rollup="min"`, `rollup="max"` and `rollup="avg"` additional labels. The calculations are performed individually per each time series returned from the given . Optional 2nd argument `"min"`, `"max"` or `"avg"` can be passed to keep only one calculation result and without adding a label. See also . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `rollupderiv(seriesselector, which calculates per-second derivatives for adjacent raw samples on the given lookbehind window `d` and returns `min`, `max` and `avg` values for the calculated per-second derivatives and returns them in time series with `rollup="min"`, `rollup="max"` and `rollup="avg"` additional labels. The calculations are performed individually per each time series returned from the given . Optional 2nd argument `"min"`, `"max"` or `"avg"` can be passed to keep only one calculation result and without adding a label. See also . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. `rollupincrease(seriesselector, which calculates increases for adjacent raw samples on the given lookbehind window `d` and returns `min`, `max` and `avg` values for the calculated increases and returns them in time series with `rollup="min"`, `rollup="max"` and `rollup="avg"` additional labels. The calculations are performed individually per each time series returned from the given . Optional 2nd argument `"min"`, `"max"` or `"avg"` can be passed to keep only one calculation result and without adding a label. See also . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `rolluprate(seriesselector, which calculates per-second change rates for adjacent raw samples on the given lookbehind window `d` and returns `min`, `max` and `avg` values for the calculated per-second change rates and returns them in time series with `rollup="min"`, `rollup="max"` and `rollup="avg"` additional labels. See in order to understand better when to use `rollup_rate()`. Optional 2nd argument `"min"`, `"max"` or `"avg"` can be passed to keep only one calculation result and without adding a label. See also . The calculations are performed individually per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric

`rollupscrapeinterval(series_selector, which calculates the interval in seconds between adjacent raw samples on the given lookbehind window `d` and returns `min`, `max` and `avg` values for the calculated interval and returns them in time series with `rollup="min"`, `rollup="max"` and `rollup="avg"` additional labels. The calculations are performed individually per each time series returned from the given . Optional 2nd argument `"min"`, `"max"` or `"avg"` can be passed to keep only one calculation result and without adding a label. See also . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `scrapeinterval(seriesselector, which calculates the average interval in seconds between raw samples on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `sharegtovertime(seriesselector, which returns share (in the range `[0...1]`) of raw samples on the given lookbehind window `d`, which are bigger than `gt`. It is calculated independently per each time series returned from the given . This function is useful for calculating SLI and SLO. Example: `sharegtover_time(up[24h], 0)` - returns service availability for the last 24 hours. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also and . `shareleovertime(seriesselector, which returns share (in the range `[0...1]`) of raw samples on the given lookbehind window `d`, which are smaller or equal to `le`. It is calculated independently per each time series returned from the given . This function is useful for calculating SLI and SLO. Example: `shareleovertime(memoryusage_bytes[24h], 10010241024)` returns the share of time series values for the last 24 hours when memory usage was below or equal to 100MB. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also and . `shareeqovertime(seriesselector, which returns share (in the range `[0...1]`) of raw samples on the given lookbehind window `d`, which are equal to `eq`. It is calculated independently per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `stalesamplesovertime(seriesselector, which calculates the number of on the given lookbehind window `d` per each time series matching the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. `stddevovertime(series_selector, which calculates standard deviation over raw samples on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. See also . `stdvarovertime(series_selector, which calculates standard variance over raw samples on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. See also . `sumeqovertime(seriesselector, which calculates the sum of raw sample values equal to `eq` on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also and . `sumgtovertime(seriesselector, which calculates the sum of raw sample values bigger than `gt` on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also and . `sumleovertime(seriesselector, which calculates the sum of raw sample values smaller or equal to `le` on the given lookbehind window `d` per each time series returned from the given

Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also and . `sumovertime(series_selector, which calculates the sum of raw sample values on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. `sum2overtime(series_selector, which calculates the sum of squares for raw sample values on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. `timestamp(series_selector, which returns the timestamp in seconds with millisecond precision for the last raw sample on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. This function is supported by PromQL. See also and . `timestampwithname(series_selector, which returns the timestamp in seconds with millisecond precision for the last raw sample on the given lookbehind window `d` per each time series returned from the given . Metric names are preserved in the resulting rollups. See also and modifier. `tfirstovertime(series_selector, which returns the timestamp in seconds with millisecond precision for the first raw sample on the given lookbehind window `d` per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `tlastchangeovertime(seriesselector, which returns the timestamp in seconds with millisecond precision for the last change per each time series returned from the given on the given lookbehind window `d`. Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `tlastovertime(series_selector, which is an alias for . See also . `tmaxovertime(series_selector, which returns the timestamp in seconds with millisecond precision for the raw sample with the maximum value on the given lookbehind window `d`. It is calculated independently per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `tminovertime(series_selector, which returns the timestamp in seconds with millisecond precision for the raw sample with the minimum value on the given lookbehind window `d`. It is calculated independently per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also . `zscoreovertime(series_selector, which returns for raw samples on the given lookbehind window `d`. It is calculated independently per each time series returned from the given . Metric names are stripped from the resulting rollups. Add modifier in order to keep metric names. See also , and . Transform functions calculate transformations over . For example, `abs(delta(temperature[24h]))` calculates the absolute value for every point of every time series returned from the rollup `delta(temperature[24h])`. Additional details: If transform function is applied directly to a , then the function is automatically applied before calculating the transformations. For example, `abs(temperature)` is implicitly transformed to `abs(default_rollup(temperature))`. All the transform functions accept optional `keepmetricnames` modifier. If it is set, then the function doesn't drop metric names from the resulting time series. See . See also . The list of supported transform functions: `abs(q)` is a , which calculates the absolute value for every point of every time series returned by `q`. This function is supported by PromQL. `absent(q)` is a , which returns 1 if `q` has no

Otherwise, returns an empty result. This function is supported by PromQL. See also . `acos(q)` is a , which returns for every point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also and . `acosh(q)` is a , which returns for every point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also . `asin(q)` is a , which returns for every point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also and . `asinh(q)` is a , which returns for every point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also . `atan(q)` is a , which returns for every point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also . `atanh(q)` is a , which returns for every point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also . `bitmap_and(q, mask)` is a , which calculates bitwise `v & mask` for every `v` point of every time series returned from `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. `bitmap_or(q, mask)` is a , which calculates bitwise `v | mask` for every `v` point of every time series returned from `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. `bitmap_xor(q, mask)` is a , which calculates bitwise `v ^ mask` for every `v` point of every time series returned from `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. `buckets_limit(limit, buckets)` is a , which limits the number of to the given `limit`. See also and . `ceil(q)` is a , which rounds every point for every time series returned by `q` to the upper nearest integer. This function is supported by PromQL. See also and . `clamp(q, min, max)` is a , which clamps every point for every time series returned by `q` with the given `min` and `max` values. This function is supported by PromQL. See also and . `clamp_max(q, max)` is a , which clamps every point for every time series returned by `q` with the given `max` value. This function is supported by PromQL. See also and . `clamp_min(q, min)` is a , which clamps every point for every time series returned by `q` with the given `min` value. This function is supported by PromQL. See also and . `cos(q)` is a , which returns `cos(v)` for every `v` point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also . `cosh(q)` is a , which returns for every point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric

This function is supported by PromQL. See also . `dayofmonth(q)` is a , which returns the day of month for every point of every time series returned by `q`. It is expected that `q` returns unix timestamps. The returned values are in the range `[1...31]`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also and . `dayofweek(q)` is a , which returns the day of week for every point of every time series returned by `q`. It is expected that `q` returns unix timestamps. The returned values are in the range `[0...6]`, where `0` means Sunday and `6` means Saturday. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also and . `dayofyear(q)` is a , which returns the day of year for every point of every time series returned by `q`. It is expected that `q` returns unix timestamps. The returned values are in the range `[1...365]` for non-leap years, and `[1 to 366]` in leap years. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also and . `daysinmonth(q)` is a , which returns the number of days in the month identified by every point of every time series returned by `q`. It is expected that `q` returns unix timestamps. The returned values are in the range `[28...31]`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. `deg(q)` is a , which converts for every point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also . `dropemptyseries(q)` is a , which drops empty series from `q`. This function can be used when `default` operator should be applied only to non-empty series. For example, `dropemptyseries(temperature < 30) default 42` returns series, which have at least a single sample smaller than 30 on the selected time range, while filling gaps in the returned series with 42. On the other hand `(temperature < 30) default 40` returns all the `temperature` series, even if they have no samples smaller than 30, by replacing all the values bigger or equal to 30 with 40. `end()` is a , which returns the unix timestamp in seconds for the last point. It is known as `end` query arg passed to . See also , and . `exp(q)` is a , which calculates the `e^v` for every point `v` of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also . `floor(q)` is a , which rounds every point for every time series returned by `q` to the lower nearest integer. This function is supported by PromQL. See also and . `histogram_avg(buckets)` is a , which calculates the average value for the given `buckets`. It can be used for calculating the average over the given time range across multiple time series. For example, `histogramavg(sum(histogramovertime(responsetimedurationseconds[5m])) by (vmrange,job))` would return the average response time per each `job` over the last 5 minutes. `histogram_quantile(phi, buckets)` is a , which calculates `phi`- over the given . `phi` must be in the range `[0...1]`. For example,

sum(rate(httprequestdurationseconds_bucket[5m])) by (le))` would return median request duration for all the requests during the last 5 minutes. The function accepts optional third arg - `boundsLabel`. In this case it returns `lower` and `upper` bounds for the estimated percentile with the given `boundsLabel` label. See . When the is calculated over multiple histograms, then all the input histograms must have buckets with identical boundaries, e.g. they must have the same set of `le` or `vmrange` labels. Otherwise, the returned result may be invalid. See for details. This function is supported by PromQL (except of the `boundLabel` arg). See also , and . `histogram_quantiles("phiLabel", phi1, ..., phiN, buckets)` is a , which calculates the given `phi*`-quantiles over the given . Argument `phi*` must be in the range `[0...1]`. For example, `histogramquantiles('le', 0.3, 0.5, sum(rate(httprequestdurationseconds_bucket[5m]) by (le))`. Each calculated quantile is returned in a separate time series with the corresponding `{phiLabel="phi*"}` label. See also . `histogram_share(le, buckets)` is a , which calculates the share (in the range `[0...1]`) for `buckets` that fall below `le`. This function is useful for calculating SLI and SLO. This is inverse to . The function accepts optional third arg - `boundsLabel`. In this case it returns `lower` and `upper` bounds for the estimated share with the given `boundsLabel` label. `histogram_stddev(buckets)` is a , which calculates standard deviation for the given `buckets`. `histogram_stdvar(buckets)` is a , which calculates standard variance for the given `buckets`. It can be used for calculating standard deviation over the given time range across multiple time series. For example, `histogramstdvar(sum(histogramover_time(temperature[24])) by (vmrange,country))` would return standard deviation for the temperature per each country over the last 24 hours. `hour(q)` is a , which returns the hour for every point of every time series returned by `q`. It is expected that `q` returns unix timestamps. The returned values are in the range `[0...23]`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. `interpolate(q)` is a , which fills gaps with linearly interpolated values calculated from the last and the next non-empty points per each time series returned by `q`. See also and . `keeplastvalue(q)` is a , which fills gaps with the value of the last non-empty point in every time series returned by `q`. See also and . `keepnextvalue(q)` is a , which fills gaps with the value of the next non-empty point in every time series returned by `q`. See also and . `limit_offset(limit, offset, q)` is a , which skips `offset` time series from series returned by `q` and then returns up to `limit` of the remaining time series per each group. This allows implementing simple paging for `q` time series. See also . `ln(q)` is a , which calculates `ln(v)` for every point `v` of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also and . `log2(q)` is a , which calculates `log2(v)` for every point `v` of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also and . `log10(q)` is a , which calculates `log10(v)` for every point `v` of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also and

`minute(q)` is a , which returns the minute for every point of every time series returned by `q`. It is expected that `q` returns unix timestamps. The returned values are in the range `[0...59]`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. `month(q)` is a , which returns the month for every point of every time series returned by `q`. It is expected that `q` returns unix timestamps. The returned values are in the range `[1...12]`, where `1` means January and `12` means December. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. `now()` is a , which returns the current timestamp as a floating-point value in seconds. See also . `pi()` is a , which returns . This function is supported by PromQL. `rad(q)` is a , which converts for every point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. See also . `prometheus_buckets(buckets)` is a , which converts with `vmrange` labels to Prometheus histogram buckets with `le` labels. This may be useful for building heatmaps in Grafana. See also and . `rand(seed)` is a , which returns pseudo-random numbers on the range `[0...1]` with even distribution. Optional `seed` can be used as a seed for pseudo-random number generator. See also and . `rand_exponential(seed)` is a , which returns pseudo-random numbers with . Optional `seed` can be used as a seed for pseudo-random number generator. See also and . `rand_normal(seed)` is a , which returns pseudo-random numbers with . Optional `seed` can be used as a seed for pseudo-random number generator. See also and . `range_avg(q)` is a , which calculates the avg value across points per each time series returned by `q`. `range_first(q)` is a , which returns the value for the first point per each time series returned by `q`. `range_last(q)` is a , which returns the value for the last point per each time series returned by `q`. `rangelinearregression(q)` is a , which calculates over the selected time range per each time series returned by `q`. This function is useful for capacity planning and predictions. `range_mad(q)` is a , which calculates the across points per each time series returned by `q`. See also and . `range_max(q)` is a , which calculates the max value across points per each time series returned by `q`. `range_median(q)` is a , which calculates the median value across points per each time series returned by `q`. `range_min(q)` is a , which calculates the min value across points per each time series returned by `q`. `range_normalize(q1, ...)` is a , which normalizes values for time series returned by `q1, ...` into `[0 ... 1]` range. This function is useful for correlating time series with distinct value ranges. See also . `range_quantile(phi, q)` is a , which returns `phi`-quantile across points per each time series returned by `q`. `phi` must be in the range `[0...1]`. `range_stddev(q)` is a , which calculates per each time series returned by `q` on the selected time range. `range_stdvar(q)` is a , which calculates per each time series returned by `q` on the selected time range. `range_sum(q)` is a , which calculates the sum of points per each time series returned by `q`. `rangetrimoutliers(k, q)` is a , which drops points located farther than `k*range_mad(q)` from the `rangemedian(q)`. E.g. it is equivalent to the following query: `q ifnot (abs(q - rangemedian(q)) > k*range_mad(q))`. See also and

`rangetrimspikes(phi, q)` is a , which drops `phi` percent of biggest spikes from time series returned by `q`. The `phi` must be in the range `[0..1]`, where `0` means `0%` and `1` means `100%`. See also and . `rangetrimzscore(z, q)` is a , which drops points located farther than `z*range_stddev(q)` from the `rangeavg(q)`. E.g. it is equivalent to the following query: `q ifnot (abs(q - rangeavg(q)) > z*range_avg(q))`. See also and . `range_zscore(q)` is a , which calculates for points returned by `q`, e.g. it is equivalent to the following query: `(q - rangeavg(q)) / rangestddev(q)`. `remove_resets(q)` is a , which removes counter resets from time series returned by `q`. `round(q, nearest)` is a , which rounds every point of every time series returned by `q` to the `nearest` multiple. If `nearest` is missing then the rounding is performed to the nearest integer. This function is supported by PromQL. See also and . `ru(free, max)` is a , which calculates resource utilization in the range `[0%...100%]` for the given `free` and `max` resources. For instance, `ru(nodememoryMemFreebytes, nodememoryMemTotalbytes)` returns memory utilization over metrics. `running_avg(q)` is a , which calculates the running avg per each time series returned by `q`. `running_max(q)` is a , which calculates the running max per each time series returned by `q`. `running_min(q)` is a , which calculates the running min per each time series returned by `q`. `running_sum(q)` is a , which calculates the running sum per each time series returned by `q`. `scalar(q)` is a , which returns `q` if `q` contains only a single time series. Otherwise, it returns nothing. This function is supported by PromQL. `sgn(q)` is a , which returns `1` if `v>0`, `-1` if `v<0` and `0` if `v==0` for every point `v` of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. `sin(q)` is a , which returns `sin(v)` for every `v` point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by MetricsQL. See also . `sinh(q)` is a , which returns for every point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by MetricsQL. See also . `tan(q)` is a , which returns `tan(v)` for every `v` point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by MetricsQL. See also . `tanh(q)` is a , which returns for every point of every time series returned by `q`. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by MetricsQL. See also . `smooth_exponential(q, sf)` is a , which smooths points per each time series returned by `q` using with the given smooth factor `sf`. `sort(q)` is a , which sorts series in ascending order by the last point in every time series returned by `q`. This function is supported by PromQL. See also and . `sort_desc(q)` is a , which sorts series in descending order by the last point in every time series returned by `q`. This function is supported by PromQL. See also and . `sqrt(q)` is a , which calculates square root for every point of every time series returned by

Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. `start()` is a , which returns unix timestamp in seconds for the first point. It is known as `start` query arg passed to . See also , and . `step()` is a , which returns the step in seconds (aka interval) between the returned points. It is known as `step` query arg passed to . See also and . `time()` is a , which returns unix timestamp for every returned point. This function is supported by PromQL. See also , , and . `timezone_offset(tz)` is a , which returns offset in seconds for the given timezone `tz` relative to UTC. This can be useful when combining with datetime-related functions. For example, `dayofweek(time()+timezoneoffset("America/LosAngeles"))` would return weekdays for `America/Los_Angeles` time zone. Special `Local` time zone can be used for returning an offset for the time zone set on the host where VictoriaMetrics runs. See . `ttf(free)` is a , which estimates the time in seconds needed to exhaust `free` resources. For instance, `ttf(nodefilesystemavail_byte)` returns the time to storage space exhaustion. This function may be useful for capacity planning. `union(q1, ..., qN)` is a , which returns a union of time series returned from `q1`, ..., `qN`. The `union` function name can be skipped - the following queries are equivalent: `union(q1, q2)` and `(q1, q2)`. It is expected that each `q*` query returns time series with unique sets of labels. Otherwise, only the first time series out of series with identical set of labels is returned. Use and functions for giving unique labelsets per each `q*` query: `vector(q)` is a , which returns `q`, e.g. it does nothing in MetricsQL. This function is supported by PromQL. `year(q)` is a , which returns the year for every point of every time series returned by `q`. It is expected that `q` returns unix timestamps. Metric names are stripped from the resulting series. Add modifier in order to keep metric names. This function is supported by PromQL. Label manipulation functions perform manipulations with labels on the selected . Additional details: If label manipulation function is applied directly to a , then the function is automatically applied before performing the label transformation. For example, `alias(temperature, "foo")` is implicitly transformed to `alias(default_rollup(temperature), "foo")`. See also . The list of supported label manipulation functions: `alias(q, "name")` is , which sets the given `name` to all the time series returned by `q`. For example, `alias(up, "foobar")` would rename `up` series to `foobar` series. `dropcommonlabels(q1, ...., qN)` is , which drops common `label="value"` pairs among time series returned from `q1, ..., qN`. `labelcopy(q, "srclabel1", "dstlabel1", ..., "srclabelN", "dst_labelN")` is , which copies label values from `srclabel*` to `dstlabel*` for all the time series returned by `q`. If `srclabel` is empty, then the corresponding `dstlabel` is left untouched. `label_del(q, "label1", ..., "labelN")` is , which deletes the given `label*` labels from all the time series returned by `q`. `labelgraphitegroup(q, groupNum1, ... groupNumN)` is , which replaces metric names returned from `q` with the given Graphite group values concatenated via `.` char. For example, `labelgraphitegroup({graphite="foo.bar."}, 0, 2)` would substitute `foo<anyvalue>.bar.<othervalue>` metric names with `foo<anyvalue>.<othervalue>`. This function is useful for aggregating Graphite metrics with . For example, the following query would return per-app memory usage: ``` sum by (name) ( labelgraphitegroup({graphite="app.host.memory_usage"}, 0) ) ``` `labeljoin(q, "dstlabel", "separator", "srclabel1", ..., "srclabelN")` is , which joins `srclabel*` values with the given `separator` and stores the result in `dstlabel`. This is performed individually per each time series returned by

For example, `label_join(up{instance="xxx",job="yyy"}, "foo", "-", "instance", "job")` would store `xxx-yyy` label value into `foo` label. This function is supported by PromQL. `label_keep(q, "label1", ..., "labelN")` is , which deletes all the labels except of the listed `label*` labels in all the time series returned by `q`. `label_lowercase(q, "label1", ..., "labelN")` is , which lowercases values for the given `label*` labels in all the time series returned by `q`. `labelmap(q, "label", "srcvalue1", "dstvalue1", ..., "srcvalueN", "dst_valueN")` is , which maps `label` values from `src_` to `dst` for all the time series returned by `q`. `label_match(q, "label", "regexp")` is , which drops time series from `q` with `label` not matching the given `regexp`. This function can be useful after -like functions, which may return multiple time series for every input series. See also and . `label_mismatch(q, "label", "regexp")` is , which drops time series from `q` with `label` matching the given `regexp`. This function can be useful after -like functions, which may return multiple time series for every input series. See also and . `labelmove(q, "srclabel1", "dstlabel1", ..., "srclabelN", "dst_labelN")` is , which moves label values from `srclabel*` to `dstlabel*` for all the time series returned by `q`. If `srclabel` is empty, then the corresponding `dstlabel` is left untouched. `labelreplace(q, "dstlabel", "replacement", "src_label", "regex")` is , which applies the given `regex` to `srclabel` and stores the `replacement` in `dstlabel` if the given `regex` matches `src_label`. The `replacement` may contain references to regex captures such as `$1`, `$2`, etc. These references are substituted by the corresponding regex captures. For example, `label_replace(up{job="node-exporter"}, "foo", "bar-$1", "job", "node-(.+)")` would store `bar-exporter` label value into `foo` label. This function is supported by PromQL. `label_set(q, "label1", "value1", ..., "labelN", "valueN")` is , which sets `{label1="value1", ..., labelN="valueN"}` labels to all the time series returned by `q`. `label_transform(q, "label", "regexp", "replacement")` is , which substitutes all the `regexp` occurrences by the given `replacement` in the given `label`. `label_uppercase(q, "label1", ..., "labelN")` is , which uppercases values for the given `label*` labels in all the time series returned by `q`. See also . `label_value(q, "label")` is , which returns numeric values for the given `label` for every time series returned by `q`. For example, if `label_value(foo, "bar")` is applied to `foo{bar="1.234"}`, then it will return a time series `foo{bar="1.234"}` with `1.234` value. Function will return no data for non-numeric label values. `labels_equal(q, "label1", "label2", ...)` is , which returns `q` series with identical values for the listed labels "label1", "label2", etc. See also and . `sortbylabel(q, "label1", ... "labelN")` is , which sorts series in ascending order by the given set of labels. For example, `sortbylabel(foo, "bar")` would sort `foo` series by values of the label `bar` in these series. See also and . `sortbylabel_desc(q, "label1", ... "labelN")` is , which sorts series in descending order by the given set of labels. For example, `sortbylabel(foo, "bar")` would sort `foo` series by values of the label `bar` in these series. See also and . `sortbylabel_numeric(q, "label1", ... "labelN")` is , which sorts series in ascending order by the given set of labels using . For example, if `foo` series have `bar` label with values `1`, `101`, `15` and `2`, then `sortbylabel_numeric(foo, "bar")` would return series in the following order of `bar` label values: `1`, `2`, `15` and `101`. See also and . `sortbylabelnumericdesc(q, "label1", ... "labelN")` is , which sorts series in descending order by the given set of labels using

For example, if `foo` series have `bar` label with values `1`, `101`, `15` and `2`, then `sortbylabel_numeric(foo, "bar")` would return series in the following order of `bar` label values: `101`, `15`, `2` and `1`. See also and . Aggregate functions calculate aggregates over groups of . Additional details: By default, a single group is used for aggregation. Multiple independent groups can be set up by specifying grouping labels in `by` and `without` modifiers. For example, `count(up) by (job)` would group by `job` label value and calculate the aggregate function independently per each group, while `count(up) without (instance)` would group by all the labels except `instance` before calculating aggregate function independently per each group. Multiple labels can be put in `by` and `without` modifiers. If the aggregate function is applied directly to a , then the function is automatically applied before calculating the aggregate. For example, `count(up)` is implicitly transformed to `count(default_rollup(up))`. Aggregate functions accept arbitrary number of args. For example, `avg(q1, q2, q3)` would return the average values for every point across time series returned by `q1`, `q2` and `q3`. Aggregate functions support optional `limit N` suffix, which can be used for limiting the number of output groups. For example, `sum(x) by (y) limit 3` limits the number of groups for the aggregation to 3. All the other groups are ignored. See also . The list of supported aggregate functions: `any(q) by (grouplabels)` is , which returns a single series per `grouplabels` out of time series returned by `q`. See also . `avg(q) by (grouplabels)` is , which returns the average value per `grouplabels` for time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. This function is supported by PromQL. `bottomk(k, q)` is , which returns up to `k` points with the smallest values across all the time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. This function is supported by PromQL. See also , and . `bottomkavg(k, q, "otherlabel=other_value")` is , which returns up to `k` time series from `q` with the smallest averages. If an optional `otherlabel=othervalue` arg is set, then the sum of the remaining time series is returned with the given label. For example, `bottomkavg(3, sum(processresidentmemorybytes) by (job), "job=other")` would return up to 3 time series with the smallest averages plus a time series with `{job="other"}` label with the sum of the remaining series if any. See also . `bottomklast(k, q, "otherlabel=other_value")` is , which returns up to `k` time series from `q` with the smallest last values. If an optional `otherlabel=othervalue` arg is set, then the sum of the remaining time series is returned with the given label. For example, `bottomkmax(3, sum(processresidentmemorybytes) by (job), "job=other")` would return up to 3 time series with the smallest maximums plus a time series with `{job="other"}` label with the sum of the remaining series if any. See also . `bottomkmax(k, q, "otherlabel=other_value")` is , which returns up to `k` time series from `q` with the smallest maximums. If an optional `otherlabel=othervalue` arg is set, then the sum of the remaining time series is returned with the given label. For example, `bottomkmax(3, sum(processresidentmemorybytes) by (job), "job=other")` would return up to 3 time series with the smallest maximums plus a time series with `{job="other"}` label with the sum of the remaining series if any. See also . `bottomkmedian(k, q, "otherlabel=other_value")` is , which returns up to `k` time series from `q` with the smallest medians. If an optional`otherlabel=othervalue` arg is set, then the sum of the remaining time series is returned with the given

For example, `bottomkmedian(3, sum(processresidentmemorybytes) by (job), "job=other")` would return up to 3 time series with the smallest medians plus a time series with `{job="other"}` label with the sum of the remaining series if any. See also . `bottomkmin(k, q, "otherlabel=other_value")` is , which returns up to `k` time series from `q` with the smallest minimums. If an optional `otherlabel=othervalue` arg is set, then the sum of the remaining time series is returned with the given label. For example, `bottomkmin(3, sum(processresidentmemorybytes) by (job), "job=other")` would return up to 3 time series with the smallest minimums plus a time series with `{job="other"}` label with the sum of the remaining series if any. See also . `count(q) by (grouplabels)` is , which returns the number of non-empty points per `grouplabels` for time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. This function is supported by PromQL. `count_values("label", q)` is , which counts the number of points with the same value and stores the counts in a time series with an additional `label`, which contains each initial value. The aggregate is calculated individually per each group of points with the same timestamp. This function is supported by PromQL. See also and . `distinct(q)` is , which calculates the number of unique values per each group of points with the same timestamp. See also . `geomean(q)` is , which calculates geometric mean per each group of points with the same timestamp. `group(q) by (grouplabels)` is , which returns `1` per each `grouplabels` for time series returned by `q`. This function is supported by PromQL. See also . `histogram(q)` is , which calculates per each group of points with the same timestamp. Useful for visualizing big number of time series via a heatmap. See for more details. See also and . `limitk(k, q) by (grouplabels)` is , which returns up to `k` time series per each `grouplabels` out of time series returned by `q`. The returned set of time series remain the same across calls. See also . `mad(q) by (group_labels)` is , which returns the per each `group_labels` for all the time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. See also , , and . `max(q) by (grouplabels)` is , which returns the maximum value per each `grouplabels` for all the time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. This function is supported by PromQL. `median(q) by (grouplabels)` is , which returns the median value per each `grouplabels` for all the time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. `min(q) by (grouplabels)` is , which returns the minimum value per each `grouplabels` for all the time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. This function is supported by PromQL. `mode(q) by (group_labels)` is , which returns ) per each `group_labels` for all the time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. `outliers_iqr(q)` is , which returns time series from `q` with at least a single point outside e.g. `[q25-1.5iqr .. q75+1.5iqr]` comparing to other time series at the given point, where: `iqr` is an calculated independently per each point on the graph across `q` series. `q25` and `q75` are 25th and 75th calculated independently per each point on the graph across `q` series. The `outliersiqr()` is useful for detecting anomalous series in the group of

For example, `outliersiqr(temperature) by (country)` returns per-country series with anomalous outlier values comparing to the rest of per-country series. See also , and . `outliers_mad(tolerance, q)` is , which returns time series from `q` with at least a single point outside (aka MAD) multiplied by `tolerance`. E.g. it returns time series with at least a single point below `median(q) - mad(q)` or a single point above `median(q) + mad(q)`. See also , and . `outliersk(k, q)` is , which returns up to `k` time series with the biggest standard deviation (aka outliers) out of time series returned by `q`. See also and . `quantile(phi, q) by (grouplabels)` is , which calculates `phi`-quantile per each `grouplabels` for all the time series returned by `q`. `phi` must be in the range `[0...1]`. The aggregate is calculated individually per each group of points with the same timestamp. This function is supported by PromQL. See also and . `quantiles("phiLabel", phi1, ..., phiN, q)` is , which calculates `phi*`-quantiles for all the time series returned by `q` and return them in time series with `{phiLabel="phi"}` label. `phi` must be in the range `[0...1]`. The aggregate is calculated individually per each group of points with the same timestamp. See also . `share(q) by (group_labels)` is , which returns shares in the range `[0..1]` for every non-negative points returned by `q` per each timestamp, so the sum of shares per each `group_labels` equals 1. This function is useful for normalizing shares into `[0..1]` range: ```metricsql share( sum( rate(httprequestdurationsecondsbucket[5m]) ) by (le, vmrange) ) ``` See also . `stddev(q) by (grouplabels)` is , which calculates standard deviation per each `grouplabels` for all the time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. This function is supported by PromQL. `stdvar(q) by (grouplabels)` is , which calculates standard variance per each `grouplabels` for all the time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. This function is supported by PromQL. `sum(q) by (grouplabels)` is , which returns the sum per each `grouplabels` for all the time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. This function is supported by PromQL. `sum2(q) by (grouplabels)` is , which calculates the sum of squares per each `grouplabels` for all the time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. `topk(k, q)` is , which returns up to `k` points with the biggest values across all the time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. This function is supported by PromQL. See also , and . `topkavg(k, q, "otherlabel=other_value")` is , which returns up to `k` time series from `q` with the biggest averages. If an optional `otherlabel=othervalue` arg is set, then the sum of the remaining time series is returned with the given label. For example, `topkavg(3, sum(processresidentmemorybytes) by (job), "job=other")` would return up to 3 time series with the biggest averages plus a time series with `{job="other"}` label with the sum of the remaining series if any. See also . `topklast(k, q, "otherlabel=other_value")` is , which returns up to `k` time series from `q` with the biggest last values. If an optional `otherlabel=othervalue` arg is set, then the sum of the remaining time series is returned with the given

For example, `topkmax(3, sum(processresidentmemorybytes) by (job), "job=other")` would return up to 3 time series with the biggest maximums plus a time series with `{job="other"}` label with the sum of the remaining series if any. See also . `topkmax(k, q, "otherlabel=other_value")` is , which returns up to `k` time series from `q` with the biggest maximums. If an optional `otherlabel=othervalue` arg is set, then the sum of the remaining time series is returned with the given label. For example, `topkmax(3, sum(processresidentmemorybytes) by (job), "job=other")` would return up to 3 time series with the biggest maximums plus a time series with `{job="other"}` label with the sum of the remaining series if any. See also . `topkmedian(k, q, "otherlabel=other_value")` is , which returns up to `k` time series from `q` with the biggest medians. If an optional `otherlabel=othervalue` arg is set, then the sum of the remaining time series is returned with the given label. For example, `topkmedian(3, sum(processresidentmemorybytes) by (job), "job=other")` would return up to 3 time series with the biggest medians plus a time series with `{job="other"}` label with the sum of the remaining series if any. See also . `topkmin(k, q, "otherlabel=other_value")` is , which returns up to `k` time series from `q` with the biggest minimums. If an optional `otherlabel=othervalue` arg is set, then the sum of the remaining time series is returned with the given label. For example, `topkmin(3, sum(processresidentmemorybytes) by (job), "job=other")` would return up to 3 time series with the biggest minimums plus a time series with `{job="other"}` label with the sum of the remaining series if any. See also . `zscore(q) by (group_labels)` is , which returns values per each `group_labels` for all the time series returned by `q`. The aggregate is calculated individually per each group of points with the same timestamp. This function is useful for detecting anomalies in the group of related time series. See also , and . MetricsQL supports and extends PromQL subqueries. See for details. Any for something other than form a subquery. Nested rollup functions can be implicit thanks to the . For example, `delta(sum(m))` is implicitly converted to `delta(sum(default_rollup(m))[1i:1i])`, so it becomes a subquery, since it contains nested into . VictoriaMetrics performs subqueries in the following way: It calculates the inner rollup function using the `step` value from the outer rollup function. For example, for expression `maxovertime(rate(httprequeststotal[5m])[1h:30s])` the inner function `rate(httprequeststotal[5m])` is calculated with `step=30s`. The resulting data points are aligned by the `step`. It calculates the outer rollup function over the results of the inner rollup function using the `step` value passed by Grafana to . VictoriaMetrics performs the following implicit conversions for incoming queries before starting the calculations: If lookbehind window in square brackets is missing inside , then it is automatically set to the following value: To `step` value passed to or for all the except of and . This value is known as `$interval` in Grafana or `1i` in MetricsQL. For example, `avgovertime(temperature)` is automatically transformed to `avgovertime(temperature[1i])`. To the `max(step, scrapeinterval)`, where `scrapeinterval` is the interval between for and functions. This allows avoiding unexpected gaps on the graph when `step` is smaller than `scrape_interval`. All the , which aren't wrapped into , are automatically wrapped into function. Examples: `foo` is transformed to `default_rollup(foo)` `foo + bar` is transformed to `defaultrollup(foo) + defaultrollup(bar)` `count(up)` is transformed to `count(default_rollup(up))`, because isn't a - it is `abs(temperature)` is transformed to `abs(default_rollup(temperature))`, because isn't a - it is If `step` in square brackets is missing inside , then `1i` step is automatically added there. For example, `avgovertime(rate(httprequeststotal[5m])[1h])` is automatically converted to `avgovertime(rate(httprequeststotal[5m])[1h:1i])`. If something other than