Expand description
§Resource Usage Tracking
This module provides functionality for tracking process resource usage, including memory and CPU utilization.
§Features
- Cross-platform memory usage tracking
- CPU usage monitoring with percentage calculations
- Sampling at configurable intervals
- Historical data collection with time-series support
§Example
ⓘ
use proc_daemon::resources::{ResourceTracker, ResourceUsage};
use std::time::Duration;
// Create a new resource tracker sampling every second
let mut tracker = ResourceTracker::new(Duration::from_secs(1));
// Get the current resource usage
let usage = tracker.current_usage();
println!("Memory: {}MB, CPU: {}%", usage.memory_mb(), usage.cpu_percent());
With tokio runtime:
ⓘ
#[cfg(feature = "tokio")]
async {
// Start tracking
tracker.start().unwrap();
// ... use the tracker ...
// Stop tracking when done
tracker.stop().await;
};
With async-std runtime:
ⓘ
#[cfg(all(feature = "async-std", not(feature = "tokio")))]
async {
// Start tracking
tracker.start().unwrap();
// ... use the tracker ...
// Stop tracking when done
tracker.stop();
};
Structs§
- Resource
Tracker - Provides resource tracking functionality for the current process
- Resource
Usage - Represents the current resource usage of the process
Enums§
- Alert
- Monitoring alerts emitted by
ResourceTracker
.