Expand description
Advanced resource management and monitoring.
This module provides resource tracking, quota enforcement, and automatic throttling for CPU, memory, disk I/O, and network bandwidth. It helps ensure the node operates within system constraints and prevents resource exhaustion.
§Example
use chie_core::resource_mgmt::{ResourceMonitor, ResourceLimits, ResourceType};
#[tokio::main]
async fn main() {
let limits = ResourceLimits::default();
let mut monitor = ResourceMonitor::new(limits);
// Check if we can allocate memory
if monitor.can_allocate(ResourceType::Memory, 1024 * 1024 * 100) {
println!("Can allocate 100MB");
monitor.record_allocation(ResourceType::Memory, 1024 * 1024 * 100);
}
// Get usage statistics
if let Some(stats) = monitor.get_stats(ResourceType::Memory) {
println!("Memory usage: {}/{}", stats.used, stats.limit);
}
}Structs§
- Monitoring
Config - Configuration for background system resource monitoring.
- Monitoring
Handle - Handle for managing background system resource monitoring.
- Resource
Limits - Resource usage limits.
- Resource
Monitor - Resource monitor for tracking and limiting resource usage.
- Resource
Stats - Resource usage statistics.
Enums§
- Degradation
Level - Degradation level for graceful handling of resource pressure.
- Resource
Type - Type of system resource.