Skip to main content

ResourceUsage

Struct ResourceUsage 

Source
pub struct ResourceUsage {
    pub memory_usage_mb: usize,
    pub total_memory_mb: usize,
    pub process_memory_mb: Option<usize>,
    pub cpu_usage_percent: f64,
    pub cpu_usage_percent_valid: bool,
    pub gpu_usage_percent: Option<f64>,
    pub network_io_mbps: Option<f64>,
    pub disk_io_mbps: Option<f64>,
    pub active_threads: usize,
    pub timestamp: Instant,
}
Expand description

Current resource usage information

Fields§

§memory_usage_mb: usize

Memory usage in MB

§total_memory_mb: usize

Total system memory in MB (R2 fix). Populated from the real system total at collection time so memory_usage_mb can be turned into an honest percentage instead of assuming a fixed 1024 MB (1 GB) total, which pinned memory_percent/memory_utilization above 100% (and therefore alert severity at Emergency) on essentially every real machine. 0 (the Default value) means “unknown”; callers must treat that as “cannot compute a percentage”, not as “0 MB total”.

§process_memory_mb: Option<usize>

Memory this process is using, in MB, or None when the process counters are unavailable.

memory_usage_mb/total_memory_mb are system-wide and only meaningful as a ratio (which is what the memory alert thresholds compare). The allocation budget, by contrast, is a per-process figure, so comparing system-wide usage against it reports several hundred percent utilization on any real machine — the same class of error as R2, one level up. That comparison was inert only because start_monitoring was never called and current_usage stayed all-zero; every budget consumer now reads this field instead.

§cpu_usage_percent: f64

CPU usage percentage (0-100).

R1: this used to be the hardcoded literal 50.0. It is now the real system-wide CPU usage read from a persistent sysinfo::System, because CPU usage is a delta between two refreshes: a freshly built System always reports 0. Until two refreshes at least sysinfo::MINIMUM_CPU_UPDATE_INTERVAL apart have happened this field holds 0.0 and cpu_usage_percent_valid is false; consumers must check the flag rather than treating the placeholder as a measurement.

§cpu_usage_percent_valid: bool

Whether cpu_usage_percent holds a real measurement.

§gpu_usage_percent: Option<f64>

GPU usage percentage (0-100) if applicable. There is no pure-Rust, vendor-neutral way to read this, so it stays None unless an external probe supplies it.

§network_io_mbps: Option<f64>

Network I/O rate in MB/s, or None before two interface refreshes have produced a usable byte delta (R1: this used to be the literal 1.0).

§disk_io_mbps: Option<f64>

Disk I/O rate in MB/s for this process, or None before two process refreshes have produced a usable byte delta (R1: this used to be the literal 5.0).

§active_threads: usize

Number of active threads

§timestamp: Instant

Timestamp of measurement

Implementations§

Source§

impl ResourceUsage

Source

pub fn process_memory(&self) -> Option<usize>

Memory this process is using, in MB, when it could be measured.

Source

pub fn cpu_usage(&self) -> Option<f64>

Real CPU usage, or None when no valid measurement has been taken yet.

Source

pub fn memory_usage_percent(&self) -> Option<f64>

Real memory-usage percentage (R2), used / total * 100. Returns None when total_memory_mb is unknown (0) rather than fabricating a value against a wrong assumed total.

Trait Implementations§

Source§

impl Clone for ResourceUsage

Source§

fn clone(&self) -> ResourceUsage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ResourceUsage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ResourceUsage

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Serialize for ResourceUsage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V