pub struct ResourceMonitor { /* private fields */ }Expand description
Resource monitor collecting system and agent metrics.
Snapshots are automatically pushed to history when record_snapshot() is called.
Use start_sampling() to spawn a background task that periodically records snapshots.
Implementations§
Source§impl ResourceMonitor
impl ResourceMonitor
Sourcepub fn new(interval_secs: u64, history_max: usize) -> Self
pub fn new(interval_secs: u64, history_max: usize) -> Self
Create a new monitor with the given sampling interval and history size.
Sourcepub fn snapshot(&self) -> ResourceSnapshot
pub fn snapshot(&self) -> ResourceSnapshot
Take a snapshot of current resource usage.
Uses the shared sysinfo::System instance (refreshed on each call)
instead of creating a new one each time.
Sourcepub fn record_snapshot(&self)
pub fn record_snapshot(&self)
Record a snapshot into the history buffer.
Call this to push the current metrics into the history ring buffer.
Oldest entries are evicted when history_max is reached.
Sourcepub fn start_sampling(self: &Arc<Self>) -> JoinHandle<()>
pub fn start_sampling(self: &Arc<Self>) -> JoinHandle<()>
Spawn a background task that periodically records snapshots.
Returns a tokio::task::JoinHandle that can be aborted to stop sampling.
Uses the interval_secs configured at construction time.
Sourcepub fn history(&self, last_n: usize) -> Vec<ResourceSnapshot>
pub fn history(&self, last_n: usize) -> Vec<ResourceSnapshot>
Returns historical snapshots, newest first.
Sourcepub fn is_overloaded(&self) -> bool
pub fn is_overloaded(&self) -> bool
Returns true if the system is currently overloaded.
Sourcepub fn set_active_agents(&self, count: usize)
pub fn set_active_agents(&self, count: usize)
Update the active agent count.
Sourcepub fn set_pending_tasks(&self, count: usize)
pub fn set_pending_tasks(&self, count: usize)
Update the pending tasks count.
Sourcepub fn add_token_usage(&self, tokens: u64)
pub fn add_token_usage(&self, tokens: u64)
Add to the cumulative token usage counter.
Sourcepub fn overload_threshold(&self) -> OverloadThreshold
pub fn overload_threshold(&self) -> OverloadThreshold
Returns a copy of the current overload threshold.
Sourcepub fn set_overload_threshold(&self, threshold: OverloadThreshold)
pub fn set_overload_threshold(&self, threshold: OverloadThreshold)
Hot-reload overload thresholds without restart.