pub struct HistoryWindow<'a> { /* private fields */ }Expand description
A ring plus the cursor into it that a rule evaluates against.
Implementations§
Source§impl<'a> HistoryWindow<'a>
impl<'a> HistoryWindow<'a>
Sourcepub const fn new(ring: &'a HistoryRing, view: HistoryView) -> Self
pub const fn new(ring: &'a HistoryRing, view: HistoryView) -> Self
Pairs a ring with an explicit cursor.
Sourcepub const fn live(ring: &'a HistoryRing) -> Self
pub const fn live(ring: &'a HistoryRing) -> Self
Pairs a ring with a cursor following the newest sample.
Sourcepub const fn view(&self) -> HistoryView
pub const fn view(&self) -> HistoryView
The cursor, which is the HistoryView §11.1’s sketch passes.
Sourcepub const fn ring(&self) -> &'a HistoryRing
pub const fn ring(&self) -> &'a HistoryRing
The ring being read.
Sourcepub fn expected_interval(&self) -> Duration
pub fn expected_interval(&self) -> Duration
The interval history is configured to retain samples at (§8.5).
Rules that need a reference interval use this rather than assuming one second (§8.1).
Sourcepub fn selected(&self) -> Option<&'a HistoricalSample>
pub fn selected(&self) -> Option<&'a HistoricalSample>
The sample the cursor selects, or the newest one when live.
Sourcepub fn recent(
&self,
count: usize,
) -> impl DoubleEndedIterator<Item = &'a HistoricalSample>
pub fn recent( &self, count: usize, ) -> impl DoubleEndedIterator<Item = &'a HistoricalSample>
The count samples ending at the cursor, oldest first.
Resolved by absolute index, so it costs one deque lookup per sample and never scans the ring (§21 M4).
Sourcepub fn previous_sample(&self, sequence: u64) -> Option<&'a HistoricalSample>
pub fn previous_sample(&self, sequence: u64) -> Option<&'a HistoricalSample>
The newest retained sample strictly older than sequence.
Rules that compare “now” against “the previous sample” use this so they work whether or not the snapshot under evaluation has already been recorded into the ring.
Sourcepub fn count_where(
&self,
metric: HistoryMetric,
count: usize,
predicate: impl Fn(f64) -> bool,
) -> Counted
pub fn count_where( &self, metric: HistoryMetric, count: usize, predicate: impl Fn(f64) -> bool, ) -> Counted
Counts how many of the count most recent samples satisfy predicate.
predicate sees only freshly measured values: a sample whose metric was
unavailable is tallied in Counted::unavailable and never passed to the
predicate, so no rule can accidentally treat a missing reading as a zero
(§26).
Sourcepub fn count_at_least(
&self,
metric: HistoryMetric,
count: usize,
threshold: f64,
) -> Counted
pub fn count_at_least( &self, metric: HistoryMetric, count: usize, threshold: f64, ) -> Counted
Counts how many of the count most recent samples are at or above
threshold.
Sourcepub fn trend(
&self,
metric: HistoryMetric,
count: usize,
) -> Option<(f64, f64, Duration)>
pub fn trend( &self, metric: HistoryMetric, count: usize, ) -> Option<(f64, f64, Duration)>
The oldest and newest freshly measured values of metric in the window.
Returns None unless both ends were measured, because a trend computed
against a missing endpoint is a fabrication (§26). The returned duration is
the real span between the two samples, never an assumed one (§8.1).
Trait Implementations§
Source§impl<'a> Clone for HistoryWindow<'a>
impl<'a> Clone for HistoryWindow<'a>
Source§fn clone(&self) -> HistoryWindow<'a>
fn clone(&self) -> HistoryWindow<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more