pub struct HostMetricsCache { /* private fields */ }Expand description
Shared read/write handle to the latest HostMetrics snapshot.
Why: the machine-status route reads without blocking; the background task
writes. None means no sample has completed yet (first boot).
What: wraps Arc<RwLock<Option<HostMetrics>>>.
Test: cache_initialises_empty, cache_write_read_roundtrip.
Implementations§
Source§impl HostMetricsCache
impl HostMetricsCache
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty cache.
Why: start empty so the route can distinguish “not yet sampled” (503)
from a real snapshot.
What: allocates Arc<RwLock<None>>.
Test: cache_initialises_empty.
Sourcepub async fn get(&self) -> Option<HostMetrics>
pub async fn get(&self) -> Option<HostMetrics>
Read the latest snapshot (None before the first sample).
Why: the machine-status route calls this to serve without blocking.
What: acquires a read lock, clones the value, releases the lock.
Test: cache_write_read_roundtrip.
Sourcepub async fn set(&self, metrics: HostMetrics)
pub async fn set(&self, metrics: HostMetrics)
Write a new snapshot into the cache.
Why: the background task calls this after each sample.
What: acquires a write lock, replaces the inner value.
Test: cache_write_read_roundtrip.
Trait Implementations§
Source§impl Clone for HostMetricsCache
impl Clone for HostMetricsCache
Source§fn clone(&self) -> HostMetricsCache
fn clone(&self) -> HostMetricsCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HostMetricsCache
impl Debug for HostMetricsCache
Auto Trait Implementations§
impl !RefUnwindSafe for HostMetricsCache
impl !UnwindSafe for HostMetricsCache
impl Freeze for HostMetricsCache
impl Send for HostMetricsCache
impl Sync for HostMetricsCache
impl Unpin for HostMetricsCache
impl UnsafeUnpin for HostMetricsCache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more