pub struct SystemHealth { /* private fields */ }Expand description
System health monitor with process introspection.
Owns a background sampler thread (unless constructed via
SystemHealth::manual) that refreshes the cached values every
update_interval_ms. All accessor methods are lock-free atomic loads.
Implementations§
Source§impl SystemHealth
impl SystemHealth
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new system health monitor with the default refresh interval
of 1 second. A background sampler thread is spawned and joined on
Drop.
Sourcepub fn with_interval(interval: Duration) -> Self
pub fn with_interval(interval: Duration) -> Self
Create with a custom refresh interval.
interval == Duration::ZERO⇒ no sampler thread is spawned; callers must useSelf::updateto refresh the cached values (equivalent toSelf::manual).- Intervals below
50 msare clamped to50 msto prevent the sampler from becoming a CPU spin loop.
Sourcepub fn manual() -> Self
pub fn manual() -> Self
Construct a manual-mode instance with no sampler thread. Callers
must invoke Self::update to refresh the cached values.
Sourcepub fn update_interval_ms(&self) -> u64
pub fn update_interval_ms(&self) -> u64
Configured refresh interval in milliseconds. 0 indicates manual
mode (no sampler thread).
Sourcepub fn mem_used_mb(&self) -> f64
pub fn mem_used_mb(&self) -> f64
Get system memory usage in MB. Lock-free atomic load.
Sourcepub fn mem_used_gb(&self) -> f64
pub fn mem_used_gb(&self) -> f64
Get system memory usage in GB.
Sourcepub fn process_cpu_used(&self) -> f64
pub fn process_cpu_used(&self) -> f64
Get process CPU usage percentage. Lock-free atomic load.
Sourcepub fn process_mem_used_mb(&self) -> f64
pub fn process_mem_used_mb(&self) -> f64
Get process memory usage in MB. Lock-free atomic load.
Sourcepub fn thread_count(&self) -> u32
pub fn thread_count(&self) -> u32
Get process thread count. Lock-free atomic load.
Sourcepub fn health_score(&self) -> f64
pub fn health_score(&self) -> f64
Get overall system health score (0.0-100.0). Lock-free atomic load.
Sourcepub fn quick_check(&self) -> HealthStatus
pub fn quick_check(&self) -> HealthStatus
Quick health check. Lock-free atomic load.
Sourcepub fn update(&self)
pub fn update(&self)
Force immediate (synchronous) refresh of every cached metric.
Bypasses the sampler interval — useful for tests, on-demand snapshots, or manual-mode operation. Safe to call from any thread.
Sourcepub fn snapshot(&self) -> SystemSnapshot
pub fn snapshot(&self) -> SystemSnapshot
Get a detailed system snapshot. Lock-free atomic loads.
Sourcepub fn process(&self) -> ProcessStats
pub fn process(&self) -> ProcessStats
Get process-specific statistics. Lock-free atomic loads.