TimeSeries[T] stores timestamped samples with a bounded history. By default it
keeps the latest 1000 samples, and add(value) records the value with the
current monotonic timestamp. Tests can pass an explicit timestamp with
add(value, ts).
Counter[T] builds on TimeSeries[T] for monotonic counters such as packet or
byte counters. rate() returns an integer u64 units-per-second value for the
normal counter use case, while rate_float() returns a fractional float when
callers need that precision.
import timeseries
counter: timeseries.Counter[u64] = timeseries.Counter()
counter.add(u64(100))
counter.add(u64(280))
pps: ?u64 = counter.rate()
pps_float: ?float = counter.rate_float()
Both rate() and rate_float() accept an optional window in seconds:
pps_60s = counter.rate(60)
Build the module:
acton build --skip-build src/timeseries.actRun the embedded tests:
acton test --module timeseries