A sampled calculation uses aggregated values of one or more measurements as input and runs the calculation script to output a single value for each time interval processed.

Sampled calculation settings

  1. Time interval

    • The time interval at which the calculation script is run and thus outputs a value.
    • For a seconds level time interval, the seconds fraction of the timestamp of a result will be a multiple of the time interval.
      For example a time interval of 5 seconds will result in a timestamp with a seconds fraction being a multiple of 5 seconds starting from 0 seconds (0, 5, 10, .. seconds).
    • The time interval is the same for all input measurements given.
    • Subsequent time intervals do not overlap. The start time is always inclusive to the interval, and the end time is always exclusive of the interval.
      For example, subsequent calculations use the intervals [t1, t2[, [t2,t3[, [t3,t4[, ...
    • The result of the calculation is written at the timestamp of the beginning of the interval.
      For example, the result of a calculation running in the interval [t1, t2[ will write its result at timestamp t1.
  2. Interval offset

    • A seconds level offset is added to each minute before multiples of the time interval are taken into account. For example a time offset of 2 seconds, will result in a timestamp with a seconds fraction not starting from 0 seconds but from 2 seconds for each minute (2, 7, 12, .. seconds).
  3. Input measurement(s)

    • Alias: similar as the Raw calculation input measurement alias.
    • Measurement(s): similar as the Raw calculation input measurement. Although for a sampled calculation, multiple input measurements can be given, causing an output value to be solely calculated once there is new data available for all input measurements in the next time interval.
    • Aggregation type: at each time interval, an aggregated value is retrieved from an input measurement according to the aggregation type. The aggregation type may differ between multiple input measurements.
    • Default value: only available if Evaluate Insufficient Data is enabled. The default value will be used if there is no data for the input measurement.
  4. Evaluate Insufficient Data

    • If enabled the script will run regardless of the availability of data for the input measurements.
    • If disabled the script will not be run on points where there are one or more values missing for the input measurements. The calculation will write an error point with status `BadInsufficientData'
  5. Script

    • The script outputs a new value starting from the aggregated values of the input measurement(s).
    • Read further about setting up a calculation script .

Aggregation types

An overview of the possible aggregation types is listed below. Note that, depending on the datatype of the according input measurement, the aggregated value will be retrieved from a different field of the measurement. For more information about the time series data fields, checkout the influx storage model .

  • a number input measurement -> uses the value field
  • a string input measurement -> uses the value_str field
  • a boolean input measurement -> uses the value_bool field
  • an array input measurement -> uses the value field (which records the length of the array)
An input measurement having an array datatype returns an aggregated value of the array length.

More info for influx v1.x

More info for influx v2.x

count

Returns the number of non-null fields values.

integral

Returns the area under the curve for subsequent field values.

mean

Returns the arithmetic mean (average) of field values.

median

Returns the middle value from a sorted list of field values.

mode

Returns the most frequent value in a list of field values.

spread

Returns the difference between the minimum and maximum field values.

stddev

Returns the standard deviation of field values.

sum

Returns the sum of field values.

first

Returns the field value with the oldest timestamp.

last

Returns the field value with the most recent timestamp.

max

Returns the greatest field value.

min

Returns the lowest field value.

Performance

Picking a shorter time interval for a sampled calculation will cause a calculation to be triggered more frequently and thus increase the load on the active machine.

A script execution times out, if it does not complete in 10 seconds.