refactor(stats-daemon): split into cpu/mem/temp/gpu modules, add gpu support
This commit is contained in:
parent
1edd14cf30
commit
76ccc99e17
5 changed files with 532 additions and 414 deletions
25
stats-daemon/src/temp.rs
Normal file
25
stats-daemon/src/temp.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use std::fs;
|
||||
use std::io::Write;
|
||||
|
||||
pub fn read_temp_celsius() -> Option<i32> {
|
||||
let mut max: Option<i32> = None;
|
||||
for i in 0.. {
|
||||
let path = format!("/sys/class/thermal/thermal_zone{i}/temp");
|
||||
match fs::read_to_string(&path) {
|
||||
Ok(s) => {
|
||||
if let Ok(millic) = s.trim().parse::<i32>() {
|
||||
let c = millic / 1000;
|
||||
max = Some(max.map_or(c, |m: i32| m.max(c)));
|
||||
}
|
||||
}
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
max
|
||||
}
|
||||
|
||||
pub fn emit_temp(out: &mut impl Write) {
|
||||
if let Some(c) = read_temp_celsius() {
|
||||
let _ = writeln!(out, "{{\"type\":\"temp\",\"celsius\":{c}}}");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue