Skip to main content

resource_tracker/metrics/
memory.rs

1use serde::{Deserialize, Serialize};
2
3/// Memory snapshot from /proc/meminfo.
4/// All values are in **mebibytes (MiB = 1_048_576 bytes)**, standardized to
5/// match Python resource-tracker PR #9 which also adopted MiB throughout.
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct MemoryMetrics {
8    pub total_mib: u64,
9    /// Truly free RAM (`MemFree` from /proc/meminfo). Matches Python `memory_free`.
10    pub free_mib: u64,
11    /// Free + reclaimable RAM (`MemAvailable` from /proc/meminfo). Superset field.
12    pub available_mib: u64,
13    /// Used RAM excluding buffers/cache (`MemTotal - MemFree - Buffers - Cached`).
14    /// Matches Python `memory_used`.
15    pub used_mib: u64,
16    /// Fraction of total RAM in use (0.0–100.0).
17    pub used_pct: f64,
18    /// Memory used by kernel I/O buffers (MiB).
19    pub buffers_mib: u64,
20    /// Memory used by the page cache including slab-reclaimable (`Cached + SReclaimable`).
21    /// Matches Python `memory_cached`.
22    pub cached_mib: u64,
23    pub swap_total_mib: u64,
24    pub swap_used_mib: u64,
25    /// Fraction of swap in use (0.0–100.0). 0.0 when no swap is configured.
26    pub swap_used_pct: f64,
27    /// Memory used by active pages (MiB). Matches Python's `memory_active`.
28    pub active_mib: u64,
29    /// Memory used by inactive pages (MiB). Matches Python's `memory_inactive`.
30    pub inactive_mib: u64,
31}