Back to Influxdb

aggregate.rate() function

content/flux/v0/stdlib/experimental/aggregate/rate.md

latest4.2 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/experimental/aggregate/aggregate.flux#L46-L57 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

aggregate.rate() calculates the average rate of increase per window of time for each input table.

aggregate.rate() requires that input data have _start and _stop columns to calculate windows of time to operate on. Use range() to assign _start and _stop values.

This function is designed to replicate the Prometheus rate() function and should only be used with counters.

Function type signature
js
(<-tables: stream[A], every: duration, ?groupColumns: [string], ?unit: duration) => stream[B] where A: Record, B: Record

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

every

({{< req >}}) Duration of time windows.

groupColumns

List of columns to group by. Default is [].

unit

Time duration to use when calculating the rate. Default is 1s.

tables

Input data. Default is piped-forward data (<-).

Examples

Calculate the average rate of change in data

js
import "experimental/aggregate"
import "sampledata"

data =
    sampledata.int()
        |> range(start: sampledata.start, stop: sampledata.stop)

data
    |> aggregate.rate(every: 30s, unit: 1s, groupColumns: ["tag"])

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

*_start*_stop_time_value*tag
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:00Z-2t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:10Z10t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:20Z7t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:30Z17t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:40Z15t1
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:50Z4t1
*_start*_stop_time_value*tag
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:00Z19t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:10Z4t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:20Z-3t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:30Z19t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:40Z13t2
2021-01-01T00:00:00Z2021-01-01T00:01:00Z2021-01-01T00:00:50Z1t2

Output data

*_start*_stop*tag_value_time
2021-01-01T00:00:00Z2021-01-01T00:01:00Zt11.22021-01-01T00:00:30Z
2021-01-01T00:00:00Z2021-01-01T00:01:00Zt112021-01-01T00:01:00Z
*_start*_stop*tag_value_time
2021-01-01T00:00:00Z2021-01-01T00:01:00Zt22021-01-01T00:00:30Z
2021-01-01T00:00:00Z2021-01-01T00:01:00Zt22.22021-01-01T00:01:00Z

{{% /expand %}} {{< /expand-wrapper >}}