Documentation

aggregate.rate() function

Flux 0.61.0+

The aggregate.rate() function is experimental and subject to change at any time. By using this function, you accept the risks of experimental functions.

The aggregate.rate() function calculates the rate of change per windows of time for each input table.

import "experimental/aggregate"

aggregate.rate(
  every: 1m,
  groupColumns: ["column1", "column2"],
  unit: 1s
)

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.

Parameters

every

(Required) Duration of time windows.

groupColumns

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

unit

The 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 sample data

The following example uses data provided by the sampledata package to show how aggregate.rate() transforms data.

import "experimental/aggregate"
import "sampledata"

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

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

View input and output

Function definition

package aggregate

import "experimental"

rate = (tables=<-, every, groupColumns=[], unit=1s) =>
  tables
    |> derivative(nonNegative:true, unit:unit)
    |> aggregateWindow(every: every, fn : (tables=<-, column) =>
      tables
        |> mean(column: column)
        |> group(columns: groupColumns)
        |> experimental.group(columns: ["_start", "_stop"], mode:"extend")
        |> sum()
    )

Used functions:
aggregateWindow()
derivative()
experimental.group()
group()
mean()
sum()


Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.