feat(agent): métriques disque et température
This commit is contained in:
@@ -1,5 +1,34 @@
|
||||
use sysinfo::Disks;
|
||||
|
||||
pub fn get(_disks: &Disks) -> (u64, u64, u64) {
|
||||
pub fn get(disks: &Disks) -> (u64, u64, u64) {
|
||||
for disk in disks.list() {
|
||||
let mount = disk.mount_point().to_string_lossy();
|
||||
if mount == "/" {
|
||||
let total = disk.total_space();
|
||||
let free = disk.available_space();
|
||||
let used = total.saturating_sub(free);
|
||||
return (used, free, total);
|
||||
}
|
||||
}
|
||||
if let Some(disk) = disks.list().first() {
|
||||
let total = disk.total_space();
|
||||
let free = disk.available_space();
|
||||
return (total.saturating_sub(free), free, total);
|
||||
}
|
||||
(0, 0, 0)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sysinfo::Disks;
|
||||
|
||||
#[test]
|
||||
fn test_disk_coherent() {
|
||||
let disks = Disks::new_with_refreshed_list();
|
||||
let (used, free, total) = get(&disks);
|
||||
if total > 0 {
|
||||
assert!(used + free <= total + 1024, "used + free > total");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
use sysinfo::Components;
|
||||
|
||||
pub fn get(_c: &Components) -> Option<f32> {
|
||||
pub fn get(components: &Components) -> Option<f32> {
|
||||
for comp in components.list() {
|
||||
let label = comp.label().to_lowercase();
|
||||
if label.contains("core 0") || label.contains("cpu") || label.contains("tdie") {
|
||||
return Some(comp.temperature());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user