pub struct PeerHealthMonitor {
pub config: MonitorConfig,
/* private fields */
}Expand description
Tracks health scores for a set of peers.
For each peer the monitor maintains a sliding window of HealthSamples
and derives a composite HealthScore every time a new sample is
recorded.
Fields§
§config: MonitorConfigConfiguration controlling thresholds, weights, and window size.
Implementations§
Source§impl PeerHealthMonitor
impl PeerHealthMonitor
Sourcepub fn new(config: MonitorConfig) -> Self
pub fn new(config: MonitorConfig) -> Self
Create a new monitor with the supplied configuration.
Sourcepub fn record_sample(&mut self, peer_id: &str, sample: HealthSample)
pub fn record_sample(&mut self, peer_id: &str, sample: HealthSample)
Record a new health observation for peer_id.
The sample is appended to the peer’s sliding window (oldest entry
discarded when the window is full) and the HealthScore is
recomputed immediately.
Sourcepub fn remove_peer(&mut self, peer_id: &str) -> bool
pub fn remove_peer(&mut self, peer_id: &str) -> bool
Remove all data for peer_id. Returns true if the peer existed.
Sourcepub fn score(&self, peer_id: &str) -> Option<&HealthScore>
pub fn score(&self, peer_id: &str) -> Option<&HealthScore>
Return the current HealthScore for peer_id, or None if unknown.
Sourcepub fn healthy_peers(&self) -> Vec<&str>
pub fn healthy_peers(&self) -> Vec<&str>
Return the IDs of all peers currently classified as HealthStatus::Healthy.
Sourcepub fn unhealthy_peers(&self) -> Vec<&str>
pub fn unhealthy_peers(&self) -> Vec<&str>
Return the IDs of all peers currently classified as HealthStatus::Unhealthy.
Sourcepub fn degraded_peers(&self) -> Vec<&str>
pub fn degraded_peers(&self) -> Vec<&str>
Return the IDs of all peers currently classified as HealthStatus::Degraded.
Auto Trait Implementations§
impl Freeze for PeerHealthMonitor
impl RefUnwindSafe for PeerHealthMonitor
impl Send for PeerHealthMonitor
impl Sync for PeerHealthMonitor
impl Unpin for PeerHealthMonitor
impl UnsafeUnpin for PeerHealthMonitor
impl UnwindSafe for PeerHealthMonitor
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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