pub async fn read_container_stats(cgroup_path: &Path) -> Result<ContainerStats>Expand description
Read container statistics from cgroups v2 filesystem
Reads the following cgroup files:
cpu.statfor CPU usage (usage_usecfield)memory.currentfor current memory usagememory.maxfor memory limit
§Arguments
cgroup_path- Path to the container’s cgroup directory
§Returns
Ok(ContainerStats)- Container statistics on successErr(io::Error)- If any cgroup file cannot be read
§Errors
Returns an error if any cgroup file cannot be read.
§Example
use std::path::Path;
use zlayer_agent::cgroups_stats::read_container_stats;
let cgroup_path = Path::new("/sys/fs/cgroup/system.slice/zlayer-mycontainer.scope");
let stats = read_container_stats(cgroup_path).await?;
println!("CPU usage: {} usec", stats.cpu_usage_usec);
println!("Memory: {} bytes", stats.memory_bytes);