Back to Influxdb

elapsed() function

content/flux/v0/stdlib/universe/elapsed.md

latest3.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/universe/universe.flux#L525-L533 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

elapsed() returns the time between subsequent records.

For each input table, elapsed() returns the same table without the first row (because there is no previous time to derive the elapsed time from) and an additional column containing the elapsed time.

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

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

Parameters

unit

Unit of time used in the calculation. Default is 1s.

timeColumn

Column to use to compute the elapsed time. Default is _time.

columnName

Column to store elapsed times in. Default is elapsed.

tables

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

Examples

Calculate the time between points in seconds

js
import "sampledata"

sampledata.int()
    |> elapsed(unit: 1s)

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

Input data

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

Output data

_time_value*tagelapsed
2021-01-01T00:00:10Z10t110
2021-01-01T00:00:20Z7t110
2021-01-01T00:00:30Z17t110
2021-01-01T00:00:40Z15t110
2021-01-01T00:00:50Z4t110
_time_value*tagelapsed
2021-01-01T00:00:10Z4t210
2021-01-01T00:00:20Z-3t210
2021-01-01T00:00:30Z19t210
2021-01-01T00:00:40Z13t210
2021-01-01T00:00:50Z1t210

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