RateTracker
python
RateTracker(window_seconds: float = 60.0) -> NoneComputes the per-minute rate of a monotonically increasing counter over a trailing time window.
Fed the cumulative counter value periodically (for example from the system-metrics loop), it returns (delta value / delta seconds) * 60 measured over the window. It tolerates the counter not advancing and irregular update intervals. Returns 0.0 until at least two samples span a positive interval.
Initialize the rate tracker.
Parameters:
window_seconds(float) – The trailing window over which the rate is averaged.
Methods
update
python
update(value: float, *, now: float | None = None) -> floatRecord the latest cumulative counter value and return the current per-minute rate.
Parameters:
value(float) – The cumulative counter value.now(float | None) – Optional timestamp override (for testing); defaults totime.time().
Returns:
float– The per-minute rate over the window, or 0.0 when not yet computable.