pub struct ResourceGuard { /* private fields */ }Expand description
Unified resource guard for monitoring all system resources.
Implementations§
Source§impl ResourceGuard
impl ResourceGuard
Sourcepub fn new(config: ResourceGuardConfig) -> Self
pub fn new(config: ResourceGuardConfig) -> Self
Create a new resource guard with the given configuration.
Sourcepub fn default_guard() -> Self
pub fn default_guard() -> Self
Create a resource guard with default configuration.
Sourcepub fn with_memory_limit(limit_mb: usize) -> Self
pub fn with_memory_limit(limit_mb: usize) -> Self
Create a resource guard with specified memory limit.
Create an Arc-wrapped resource guard for sharing across threads.
Sourcepub fn check(&self) -> SynthResult<DegradationLevel>
pub fn check(&self) -> SynthResult<DegradationLevel>
Check all resources (memory, disk, CPU). Returns Ok with current degradation level or Err if hard limits exceeded.
Sourcepub fn check_now(&self) -> SynthResult<DegradationLevel>
pub fn check_now(&self) -> SynthResult<DegradationLevel>
Force an immediate check of all resources (bypasses interval).
Sourcepub fn get_actions(&self) -> DegradationActions
pub fn get_actions(&self) -> DegradationActions
Get actions to take based on current degradation level.
Sourcepub fn is_degraded(&self) -> bool
pub fn is_degraded(&self) -> bool
Check if currently degraded (not Normal).
Sourcepub fn degradation_level(&self) -> DegradationLevel
pub fn degradation_level(&self) -> DegradationLevel
Get current degradation level.
Sourcepub fn stats(&self) -> ResourceStats
pub fn stats(&self) -> ResourceStats
Get combined resource statistics.
Sourcepub fn pre_check(&self) -> PreCheckResult
pub fn pre_check(&self) -> PreCheckResult
Pre-check before a potentially expensive operation. Returns recommended action based on current resource state.
Sourcepub fn check_before_write(&self, estimated_bytes: u64) -> SynthResult<()>
pub fn check_before_write(&self, estimated_bytes: u64) -> SynthResult<()>
Pre-check before writing data.
Sourcepub fn record_write(&self, bytes: u64)
pub fn record_write(&self, bytes: u64)
Record bytes written (for tracking).
Sourcepub fn memory(&self) -> &MemoryGuard
pub fn memory(&self) -> &MemoryGuard
Get reference to memory guard.
Sourcepub fn disk(&self) -> &DiskSpaceGuard
pub fn disk(&self) -> &DiskSpaceGuard
Get reference to disk guard.
Sourcepub fn cpu(&self) -> &CpuMonitor
pub fn cpu(&self) -> &CpuMonitor
Get reference to CPU monitor.
Sourcepub fn degradation(&self) -> &DegradationController
pub fn degradation(&self) -> &DegradationController
Get reference to degradation controller.
Sourcepub fn maybe_throttle(&self)
pub fn maybe_throttle(&self)
Apply throttle delay if CPU is overloaded.
Sourcepub fn reset_stats(&self)
pub fn reset_stats(&self)
Reset all statistics (for testing).
Sourcepub fn is_available() -> bool
pub fn is_available() -> bool
Check if resource monitoring is available on this platform.
Sourcepub fn current_memory_mb(&self) -> usize
pub fn current_memory_mb(&self) -> usize
Get current memory usage in MB.
Sourcepub fn available_disk_mb(&self) -> usize
pub fn available_disk_mb(&self) -> usize
Get current available disk space in MB.
Sourcepub fn current_cpu_load(&self) -> f64
pub fn current_cpu_load(&self) -> f64
Get current CPU load.