pub struct MetricTracker { /* private fields */ }Expand description
Per-metric ring buffer history tracker.
Implementations§
Source§impl MetricTracker
impl MetricTracker
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new metric tracker with the given capacity per metric.
Sourcepub fn record(&mut self, sample: MetricSample)
pub fn record(&mut self, sample: MetricSample)
Record a metric sample.
Sourcepub fn history(&self, kind: MetricKind) -> Option<&VecDeque<MetricSample>>
pub fn history(&self, kind: MetricKind) -> Option<&VecDeque<MetricSample>>
Get the history for a metric kind (oldest first).
Sourcepub fn latest(&self, kind: MetricKind) -> Option<&MetricSample>
pub fn latest(&self, kind: MetricKind) -> Option<&MetricSample>
Get the most recent sample for a metric kind.
Sourcepub fn sample_count(&self, kind: MetricKind) -> usize
pub fn sample_count(&self, kind: MetricKind) -> usize
Get the number of samples for a metric kind.
Sourcepub fn tracked_kinds(&self) -> impl Iterator<Item = MetricKind> + '_
pub fn tracked_kinds(&self) -> impl Iterator<Item = MetricKind> + '_
Iterate over metric kinds that have at least one sample.
Sourcepub fn tracked_count(&self) -> usize
pub fn tracked_count(&self) -> usize
Number of metrics with at least one sample.
Sourcepub fn ewma(&self, kind: MetricKind, alpha: f32) -> Option<f32>
pub fn ewma(&self, kind: MetricKind, alpha: f32) -> Option<f32>
Compute the EWMA (exponentially weighted moving average) for a metric.
Sourcepub fn slope(&self, kind: MetricKind) -> Option<f32>
pub fn slope(&self, kind: MetricKind) -> Option<f32>
Compute the linear slope (rate of change) for a metric. Returns the slope per sample (positive = increasing).
Auto Trait Implementations§
impl Freeze for MetricTracker
impl RefUnwindSafe for MetricTracker
impl Send for MetricTracker
impl Sync for MetricTracker
impl Unpin for MetricTracker
impl UnsafeUnpin for MetricTracker
impl UnwindSafe for MetricTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more