struct MainTemplate {
text_status: String,
memory: String,
- cpu: String,
+ load_average: String,
uptime: String
}
MainTemplate {
text_status: String::from("Valheim server is up and running :)"),
memory: info.format_memory(),
- cpu: info.format_cpu_usage(),
+ load_average: info.format_load_average(),
uptime: info.format_uptime()
},
None => {
let value_unknown = String::from(VALUE_UNKNOWN);
- MainTemplate { text_status: String::from("Valheim server is down :("), memory: value_unknown.clone(), cpu: value_unknown.clone(), uptime: value_unknown.clone() }
+ MainTemplate { text_status: String::from("Valheim server is down :("), memory: value_unknown.clone(), load_average: value_unknown.clone(), uptime: value_unknown.clone() }
}
}
-use std::cmp::min;\r
-\r
use sysinfo::{ ProcessExt, SystemExt };\r
\r
#[derive(Debug)]\r
pub struct ValheimExe {\r
memory: u64, // [kB].\r
- cpu_usage: f32, // [%].\r
+ load_average_5min: f64, // [%].\r
uptime: u64, // [s].\r
}\r
\r
pub fn format_memory(&self) -> String {\r
format_byte_size(self.memory * 1024, 2)\r
}\r
- pub fn format_cpu_usage(&self) -> String {\r
- format!("{:.2} %", self.cpu_usage)\r
+ pub fn format_load_average(&self) -> String {\r
+ format!("{:.2} %", self.load_average_5min)\r
}\r
pub fn format_uptime(&self) -> String {\r
let mins = self.uptime / 60;\r
String::from("")\r
}\r
\r
-const VALHEIM_PROCESS_NAME: &str = "valheim_server";\r
+const VALHEIM_PROCESS_NAME: &str = "firefox"; //valheim_server";\r
\r
pub fn get_valheim_executable_information() -> Option<ValheimExe> {\r
let mut system = sysinfo::System::new_all();\r
Some(\r
ValheimExe {\r
memory: process.memory(),\r
- cpu_usage: process.cpu_usage(),\r
+ load_average_5min: system.get_load_average().five,\r
uptime: std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() - process.start_time()\r
}\r
)\r
} else {\r
None\r
}\r
-}
\ No newline at end of file
+}\r
<body>\r
<div class="container">\r
<h1>{{ text_status }}</h1>\r
- <p>Memory: {{ memory }}</p>\r
- <p>CPU: {{ cpu }}</p>\r
+ <p>Memory used: {{ memory }}</p>\r
+ <p>Load average (5 min): {{ load_average }}</p>\r
<p>Uptime: {{ uptime }}</p>\r
</div>\r
</body>\r