Calculate Average Middleware Source ​
lua
telem.middleware.calcAvg (windowSize?: integer)
Calculates the average of each metric in a collection, observed over a number of cycles. Each average is appended to the collection as a new metric, with an _avg
suffix appended to the name, and the source set to middleware
.
Name | Type | Default |
---|---|---|
windowSize | integer | 50 |
Number of cycles to include when calculating the average. |
Methods ​
force
​
lua
CalcAverageMiddleware:force (): self
Force the middleware to process metrics from other middleware (source = 'middleware'
), default is to ignore metrics from other middleware.
Usage ​
lua
local telem = require 'telem'
local mw = telem.middleware
local backplane = telem.backplane()
:addInput('random', telem.input.custom(function ()
return { rand = math.random(1, 2) }
end))
:middleware(mw.calcAvg())
:cycleEvery(0.1)()
This will result in the following collection:
Name | Value | Unit | Adapter | Source |
---|---|---|---|---|
rand | 1 or 2 | random | ||
rand_avg | ~ 1.5 | middleware |
Observing the value over time shows that the average converges to the expected value: