Skip to main content

SystemHealth

Struct SystemHealth 

Source
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

Source

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.

Source

pub fn with_interval(interval: Duration) -> Self

Create with a custom refresh interval. Uses HealthConfig::default for the health-score thresholds.

  • interval == Duration::ZERO ⇒ no sampler thread is spawned; callers must use Self::update to refresh the cached values (equivalent to Self::manual).
  • Intervals below 50 ms are clamped to 50 ms to prevent the sampler from becoming a CPU spin loop.
Source

pub fn with_config(interval: Duration, config: HealthConfig) -> Self

Create with both a custom refresh interval and a custom HealthConfig (v0.9.5+). See Self::with_interval for interval semantics.

Source

pub fn manual() -> Self

Construct a manual-mode instance with no sampler thread. Callers must invoke Self::update to refresh the cached values.

Source

pub fn update_interval_ms(&self) -> u64

Configured refresh interval in milliseconds. 0 indicates manual mode (no sampler thread).

Source

pub fn cpu_used(&self) -> f64

Get system CPU usage percentage. Lock-free atomic load.

Source

pub fn cpu_free(&self) -> f64

Get system CPU free percentage.

Source

pub fn mem_used_mb(&self) -> f64

Get system memory usage in MB. Lock-free atomic load.

Source

pub fn mem_used_gb(&self) -> f64

Get system memory usage in GB.

Source

pub fn process_cpu_used(&self) -> f64

Get process CPU usage percentage. Lock-free atomic load.

Source

pub fn process_mem_used_mb(&self) -> f64

Get process memory usage in MB. Lock-free atomic load.

Source

pub fn load_avg(&self) -> f64

Get system load average. Lock-free atomic load.

Source

pub fn thread_count(&self) -> u32

Get process thread count. Lock-free atomic load.

Source

pub fn fd_count(&self) -> u32

Get process file descriptor count. Lock-free atomic load.

Source

pub fn health_score(&self) -> f64

Get overall system health score (0.0-100.0). Lock-free atomic load.

Source

pub fn quick_check(&self) -> HealthStatus

Quick health check. Lock-free atomic load.

Source

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.

Source

pub fn snapshot(&self) -> SystemSnapshot

Get a detailed system snapshot. Lock-free atomic loads.

Source

pub fn process(&self) -> ProcessStats

Get process-specific statistics. Lock-free atomic loads.

Trait Implementations§

Source§

impl Debug for SystemHealth

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SystemHealth

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for SystemHealth

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.