X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=backend%2Fsrc%2Fvalheim_controller.rs;h=fd6dcc434eb1c77deacc58a021bb17078f292252;hb=17b32f18e23bf3cd60f6cbcb24df6cc729d935c0;hp=cf18e08c3afec715b3de660e47959137cd29a860;hpb=752356234981aff11c98cf77d9c504095dfa6fe2;p=valheim_web.git diff --git a/backend/src/valheim_controller.rs b/backend/src/valheim_controller.rs index cf18e08..fd6dcc4 100644 --- a/backend/src/valheim_controller.rs +++ b/backend/src/valheim_controller.rs @@ -1,11 +1,9 @@ -use std::cmp::min; - use sysinfo::{ ProcessExt, SystemExt }; #[derive(Debug)] pub struct ValheimExe { memory: u64, // [kB]. - cpu_usage: f32, // [%]. + load_average_5min: f64, // [%]. uptime: u64, // [s]. } @@ -13,8 +11,8 @@ impl ValheimExe { pub fn format_memory(&self) -> String { format_byte_size(self.memory * 1024, 2) } - pub fn format_cpu_usage(&self) -> String { - format!("{:.2} %", self.cpu_usage) + pub fn format_load_average(&self) -> String { + format!("{:.2} %", self.load_average_5min) } pub fn format_uptime(&self) -> String { let mins = self.uptime / 60; @@ -44,7 +42,7 @@ fn format_byte_size(bytes: u64, precision: usize) -> String { String::from("") } -const VALHEIM_PROCESS_NAME: &str = "valheim_server"; +const VALHEIM_PROCESS_NAME: &str = "firefox"; //valheim_server"; pub fn get_valheim_executable_information() -> Option { let mut system = sysinfo::System::new_all(); @@ -57,11 +55,11 @@ pub fn get_valheim_executable_information() -> Option { Some( ValheimExe { memory: process.memory(), - cpu_usage: process.cpu_usage(), + load_average_5min: system.get_load_average().five, uptime: std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() - process.start_time() } ) } else { None } -} \ No newline at end of file +}