avg
Return the average of the values of a specified field.
put|reduce avg(field)
Parameter | Description | Required? |
---|---|---|
field |
The name of the field to average | Yes |
Example
This example uses the batch processor.
// On historical data, you can apply reducer to get a single computation,
// or batch your historical data by time, then reduce per batch period.
sub historical_points() {
emit -from :0: -limit 10
| put cnt = count(), value = Math.random()
}
historical_points
| reduce avg(value)
| view table
-title "Historical average"
;
historical_points
| batch 5
| reduce avg(value)
| view table
-update "append"
-title "Historical 5-second average"
;
// On live streaming data, you must batch by time, then reduce per batch period.
sub live_points() {
emit -limit 10
| put cnt = count(), value = Math.random()
}
live_points
| batch 2
| reduce avg(value)
| view table
-update "append"
-title "Live 2-second average"
;