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.
Trait Implementations§
Source§impl Debug for ResourceGuard
impl Debug for ResourceGuard
Auto Trait Implementations§
impl !Freeze for ResourceGuard
impl RefUnwindSafe for ResourceGuard
impl Send for ResourceGuard
impl Sync for ResourceGuard
impl Unpin for ResourceGuard
impl UnsafeUnpin for ResourceGuard
impl UnwindSafe for ResourceGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.