pub struct CounterSeries { /* private fields */ }Expand description
CounterSeries implements a time series stored in a sequence of a fixed number of buckets each with a fixed (and equal) duration.
The buckets are implemented as a ring buffer held in memory. The counter can be incremented or updated to a new value, but only for the bucket representing the current point in time.
As time elapses, the current bucket changes based on the bucket duration, with older buckets being zeroed out. No background maintenance tasks are required to manage this rotation, as the counter series maintains book keeping to fixup the structure prior to accessing the buckets.
The value tracked in each bucket is a u64, meaning that we cannot track negative numbers. If you try to delta outside the valid range, the resulting value is saturated to the bounds of a u64; it will never be less than zero and never wrap around due to overflow.
Implementations§
Source§impl CounterSeries
impl CounterSeries
Sourcepub fn with_config(config: CounterSeriesConfig) -> Self
pub fn with_config(config: CounterSeriesConfig) -> Self
Create a new instance. All buckets will be initialized to zero.
Sourcepub fn with_initial_value(config: CounterSeriesConfig, value: u64) -> Self
pub fn with_initial_value(config: CounterSeriesConfig, value: u64) -> Self
Create a new instance with a pre-set initial value. Useful when setting up the initial state for observation based tracking
Sourcepub fn increment(&mut self, to_add: u64)
pub fn increment(&mut self, to_add: u64)
Increment the counter for the current time window by the specified value.
Sourcepub fn delta(&mut self, delta: i64)
pub fn delta(&mut self, delta: i64)
Adjust the counter for the current time window by the specified value