Documentation

timeWeightedAvg() function

The timeWeightedAvg() function outputs the time-weighted average of non-null records in a table as a float. Time is weighted using the linearly interpolated integral of values in the table.

Function type: Aggregate
Output data type: Float

timeWeightedAvg(unit: "_value")

Parameters

unit

Time duration used when computing the time-weighted average.

Data type: Duration

Examples

from(bucket: "example-bucket")
  |> range(start: -5m)
  |> filter(fn: (r) =>
    r._measurement == "cpu" and
    r._field == "usage_system"
  )
  |> timeWeightedAvg(unit: 1m)

Function definition

timeWeightedAvg = (tables=<-, unit) => tables
  |> integral(
    unit: unit,
    interpolate: "linear"
  )
  |> map(fn: (r) => ({
    r with
    _value: (r._value * float(v: uint(v: unit))) / float(v: int(v: r._stop) - int(v: r._start))
  }))

New! Cloud or OSS?