pub struct StorageHealthMonitor { /* private fields */ }Expand description
Production-grade storage-subsystem health monitor.
Manages a collection of named probes, records check outcomes (success/failure + latency), computes EWMA metrics, fires alerts, and maintains a rolling history of health snapshots.
Implementations§
Source§impl StorageHealthMonitor
impl StorageHealthMonitor
Sourcepub fn new(config: ShmMonitorConfig) -> Self
pub fn new(config: ShmMonitorConfig) -> Self
Create a new monitor with the given configuration.
Sourcepub fn default_config() -> Self
pub fn default_config() -> Self
Create a monitor with default configuration.
Sourcepub fn register_probe(
&mut self,
name: impl Into<String>,
category: ShmCategory,
metadata: HashMap<String, String>,
) -> ShmProbeId
pub fn register_probe( &mut self, name: impl Into<String>, category: ShmCategory, metadata: HashMap<String, String>, ) -> ShmProbeId
Register a new probe and return its unique ShmProbeId.
Sourcepub fn record_check(
&mut self,
probe_id: ShmProbeId,
success: bool,
latency_ms: f64,
) -> Result<(), String>
pub fn record_check( &mut self, probe_id: ShmProbeId, success: bool, latency_ms: f64, ) -> Result<(), String>
Record the outcome of a health check for probe_id.
Updates EWMA success rate and latency, transitions probe status, and fires alerts when thresholds are crossed.
Returns an error string if the probe does not exist.
Sourcepub fn record_check_at(
&mut self,
probe_id: ShmProbeId,
success: bool,
latency_ms: f64,
now_ts: u64,
) -> Result<(), String>
pub fn record_check_at( &mut self, probe_id: ShmProbeId, success: bool, latency_ms: f64, now_ts: u64, ) -> Result<(), String>
Same as record_check but with an explicit Unix-epoch timestamp.
Sourcepub fn run_health_check(&mut self) -> ShmHealthSnapshot
pub fn run_health_check(&mut self) -> ShmHealthSnapshot
Compute an overall ShmHealthSnapshot and push it to the history.
Sourcepub fn run_health_check_at(&mut self, now_ts: u64) -> ShmHealthSnapshot
pub fn run_health_check_at(&mut self, now_ts: u64) -> ShmHealthSnapshot
Same as run_health_check but with an explicit timestamp.
Sourcepub fn resolve_alert(&mut self, alert_id: usize) -> Result<(), String>
pub fn resolve_alert(&mut self, alert_id: usize) -> Result<(), String>
Mark an alert as resolved by its index in the internal deque.
Sourcepub fn expire_alerts(&mut self, now_ts: u64)
pub fn expire_alerts(&mut self, now_ts: u64)
Expire all unresolved alerts whose auto_resolve_at timestamp ≤ now_ts.
Sourcepub fn active_alerts(&self) -> Vec<&ShmAlert>
pub fn active_alerts(&self) -> Vec<&ShmAlert>
Return active (unresolved) alerts.
Sourcepub fn all_alerts(&self) -> Vec<&ShmAlert>
pub fn all_alerts(&self) -> Vec<&ShmAlert>
Return all alerts (resolved and unresolved).
Sourcepub fn probes_by_category(&self, cat: ShmCategory) -> Vec<&ShmProbe>
pub fn probes_by_category(&self, cat: ShmCategory) -> Vec<&ShmProbe>
Return all probes belonging to the given category.
Sourcepub fn probe(&self, id: ShmProbeId) -> Option<&ShmProbe>
pub fn probe(&self, id: ShmProbeId) -> Option<&ShmProbe>
Return a reference to a probe by id.
Sourcepub fn health_trend(&self, window: usize) -> Vec<f64>
pub fn health_trend(&self, window: usize) -> Vec<f64>
Return the last window overall health scores from history (oldest first).
Sourcepub fn history_window(&self, window: usize) -> Vec<&ShmHealthSnapshot>
pub fn history_window(&self, window: usize) -> Vec<&ShmHealthSnapshot>
Return the last window snapshots from history (oldest first).
Sourcepub fn suggest_recovery(&self, probe_id: ShmProbeId) -> Result<String, String>
pub fn suggest_recovery(&self, probe_id: ShmProbeId) -> Result<String, String>
Produce a human-readable recovery suggestion for the given probe.
Sourcepub fn monitor_stats(&self) -> ShmMonitorStats
pub fn monitor_stats(&self) -> ShmMonitorStats
Return aggregate statistics for the monitor.
Sourcepub fn config(&self) -> &ShmMonitorConfig
pub fn config(&self) -> &ShmMonitorConfig
Return the current configuration.
Sourcepub fn set_config(&mut self, config: ShmMonitorConfig)
pub fn set_config(&mut self, config: ShmMonitorConfig)
Update the configuration at runtime.
Sourcepub fn probe_count(&self) -> usize
pub fn probe_count(&self) -> usize
Return the number of registered probes.
Sourcepub fn history_len(&self) -> usize
pub fn history_len(&self) -> usize
Return the number of stored history snapshots.
Auto Trait Implementations§
impl Freeze for StorageHealthMonitor
impl RefUnwindSafe for StorageHealthMonitor
impl Send for StorageHealthMonitor
impl Sync for StorageHealthMonitor
impl Unpin for StorageHealthMonitor
impl UnsafeUnpin for StorageHealthMonitor
impl UnwindSafe for StorageHealthMonitor
Blanket Implementations§
impl<T> Allocation for T
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