Show available RAM and measured CPU usage for devices
Rust development slice / linux (push) Failing after 8s

This commit is contained in:
2026-11-18 18:37:18 +01:00
parent fb2376443c
commit b3fe35b86b
17 changed files with 254 additions and 30 deletions
+16
View File
@@ -11,6 +11,22 @@ pub enum DeviceType {
Hypervisor,
}
#[derive(Clone, Copy)]
pub struct CpuTimes {
pub total: u64,
pub idle: u64,
}
impl CpuTimes {
pub fn usage_since(self, previous: Self) -> Option<u32> {
let total = self.total.checked_sub(previous.total)?;
let idle = self.idle.checked_sub(previous.idle)?;
let busy = total.checked_sub(idle)?;
(total != 0)
.then(|| ((u128::from(busy) * 10_000 + u128::from(total / 2)) / u128::from(total)) as u32)
}
}
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct Observation {