Calculate Delta Middleware Source ​
telem.middleware.calcDelta (windowSize?: integer)
Measures the delta and rate of each metric in a collection, in both instant and ranged variants. Each measurement is appended to the collection as a new metric, with a suffix appended to the name, and the source set to middleware
.
The instant delta is calculated as the difference between the current and previous values, and the instant rate is calculated as the delta divided by the observed time between cycles. The ranged delta and rate are similar, but the previous value is taken from windowSize
cycles ago.
Name | Type | Default |
---|---|---|
windowSize | integer | 50 |
Number of cycles to include when calculating the delta and rate. |
Methods ​
force
​
CalcDeltaMiddleware:force (): self
Force the middleware to process metrics from other middleware (source = 'middleware'
), default is to ignore metrics from other middleware.
interval
​
CalcDeltaMiddleware:interval (interval: string): self
Set the interval used to calculate the rate. The default is 1s
, which will result in the rate being calculated in units per second.
The format is (unitScale)(unit)
, where unitScale
is an integer greater than 0, and unit
is one of: s
(second), m
(minute), h
(hour), d
(day). Note that "day" is a 24-hour day, not an in-game day.
Usage ​
local telem = require 'telem'
local mw = telem.middleware
local state = 0
local backplane = telem.backplane()
:addInput('increments', telem.input.custom(function ()
state = state + 1
return { inc = state }
end))
:middleware(mw.calcDelta():interval('1m'))
:cycleEvery(0.1)()
This will result in the following collection:
Name | Value | Unit | Adapter | Source |
---|---|---|---|---|
inc | 0 - inf | increments | ||
inc_idelta | 1 | middleware | ||
inc_delta | ~ 49 | middleware | ||
inc_irate | ~ 600 | middleware | ||
inc_rate | ~ 600 | middleware |
Observing the value over time looks something like this: