Expand description
Explicit roots for monitoring agents (Linux).
A monitoring agent in a container that has the host’s root filesystem
mounted (say at /host, with the host’s /proc and /sys under it) reads
the host’s values through an explicit root. gopsutil offers the same
through the HOST_PROC and HOST_SYS environment variables; sys-lib offers
it only as a constructor in code, so no deployment can redirect a normal
program’s readings through its environment (threat T4). The readings are
the same code the rest of the crate uses on /.
The host’s mounts and network counters are read through its process 1
(/proc/1/mountinfo, /proc/1/net/dev), which is the host’s view when the
agent shares the host’s process namespace (hostPID); otherwise they are
the agent’s own. CPU, memory, disk I/O, load, and uptime are system-wide.
use sys_lib::probe::Probe;
let host = Probe::with_root("/host")?;
let m = host.memory()?;
println!("host memory {} free of {}", m.free, m.total);
let mut cpu = host.cpu_sampler()?;
std::thread::sleep(std::time::Duration::from_secs(1));
println!("host cpu {}", cpu.sample()?.used());Structs§
- Probe
- A host’s
/procand/sys, read through an explicit root.