pub struct NodeMonitor { /* private fields */ }Expand description
Tracks node health based on heartbeat records and configurable timeouts.
Implementations§
Source§impl NodeMonitor
impl NodeMonitor
Sourcepub fn new(timeout_ms: u64) -> Self
pub fn new(timeout_ms: u64) -> Self
Create a new monitor.
timeout_ms— a node is considered dead when no heartbeat has been received for this many milliseconds.
Sourcepub fn with_max_history(self, max_history: usize) -> Self
pub fn with_max_history(self, max_history: usize) -> Self
Set the maximum heartbeat history to retain per node.
Sourcepub fn register(&mut self, node: NodeInfo)
pub fn register(&mut self, node: NodeInfo)
Register a new node. Overwrites any previous registration for the same ID.
Sourcepub fn record_heartbeat(
&mut self,
node_id: &str,
received_at: u64,
latency_ms: u64,
) -> bool
pub fn record_heartbeat( &mut self, node_id: &str, received_at: u64, latency_ms: u64, ) -> bool
Record a heartbeat received from a node.
Sets the node’s state to Alive and appends the record to its history.
Returns false if the node is not registered.
Sourcepub fn check_timeouts(&mut self, now: u64) -> Vec<String>
pub fn check_timeouts(&mut self, now: u64) -> Vec<String>
Scan all registered nodes and mark those whose last heartbeat is older
than timeout_ms as Dead.
Returns the IDs of nodes that transitioned to Dead in this call.
Sourcepub fn alive_nodes(&self) -> Vec<&NodeInfo>
pub fn alive_nodes(&self) -> Vec<&NodeInfo>
Return references to all nodes whose state is Alive.
Sourcepub fn dead_nodes(&self) -> Vec<&NodeInfo>
pub fn dead_nodes(&self) -> Vec<&NodeInfo>
Return references to all nodes whose state is Dead.
Sourcepub fn avg_latency(&self, node_id: &str) -> Option<f64>
pub fn avg_latency(&self, node_id: &str) -> Option<f64>
Compute the average heartbeat latency for a node.
Returns None if the node has no heartbeat history.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Total number of registered nodes.
Sourcepub fn last_heartbeat(&self, node_id: &str) -> Option<&HeartbeatRecord>
pub fn last_heartbeat(&self, node_id: &str) -> Option<&HeartbeatRecord>
Return the most recent heartbeat record for a node, if any.
Sourcepub fn heartbeat_count(&self, node_id: &str) -> usize
pub fn heartbeat_count(&self, node_id: &str) -> usize
Number of heartbeat records stored for a node.
Auto Trait Implementations§
impl Freeze for NodeMonitor
impl RefUnwindSafe for NodeMonitor
impl Send for NodeMonitor
impl Sync for NodeMonitor
impl Unpin for NodeMonitor
impl UnsafeUnpin for NodeMonitor
impl UnwindSafe for NodeMonitor
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.