Module resource_mgmt

Module resource_mgmt 

Source
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§

MonitoringConfig
Configuration for background system resource monitoring.
MonitoringHandle
Handle for managing background system resource monitoring.
ResourceLimits
Resource usage limits.
ResourceMonitor
Resource monitor for tracking and limiting resource usage.
ResourceStats
Resource usage statistics.

Enums§

DegradationLevel
Degradation level for graceful handling of resource pressure.
ResourceType
Type of system resource.