text_status: String,
memory: String,
load_average: String,
- uptime: String
+ uptime: String,
+ world_size: String
}
#[derive(Deserialize)]
text_status: String::from("Valheim server is up and running :)"),
memory: info.format_memory(),
load_average: info.format_load_average(),
- uptime: info.format_uptime()
+ uptime: info.format_uptime(),
+ world_size: info.format_world_size()
},
None => {
let value_unknown = String::from(VALUE_UNKNOWN);
- MainTemplate { text_status: String::from("Valheim server is down :("), memory: value_unknown.clone(), load_average: 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(), world_size: value_unknown.clone() }
}
}
-use sysinfo::{ ProcessExt, SystemExt };\r
+use sysinfo::{ComponentExt, ProcessExt, SystemExt};\r
\r
#[derive(Debug)]\r
pub struct ValheimExe {\r
memory: u64, // [kB].\r
load_average_5min: f64, // [%].\r
uptime: u64, // [s].\r
+ world_size: u64, // [B].\r
}\r
\r
impl ValheimExe {\r
let days = hours / 24;\r
format!("{}d{}h{}min", days, hours - 24 * days, mins - 60 * hours)\r
}\r
+ pub fn format_world_size(&self) -> String {\r
+ format_byte_size(self.world_size, 2)\r
+ }\r
}\r
\r
const BINARY_PREFIXES: [&str; 8] = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"];\r
}\r
\r
const VALHEIM_PROCESS_NAME: &str = "valheim_server";\r
+const VALHEIM_WORLD_PATH: &str = "/home/greg/ValheimWorld/pouet.db"; // TODO: Put in conf.\r
\r
pub fn get_valheim_executable_information() -> Option<ValheimExe> {\r
let mut system = sysinfo::System::new_all();\r
- system.refresh_all();\r
+ system.refresh_system();\r
let processes = system.get_process_by_name(VALHEIM_PROCESS_NAME);\r
\r
if processes.len() >= 1 {\r
let process = processes.first().unwrap();\r
\r
+ let world_size = match std::fs::metadata(VALHEIM_WORLD_PATH) { Ok(f) => f.len(), Err(_) => 0u64 };\r
+\r
Some(\r
ValheimExe {\r
memory: process.memory(),\r
load_average_5min: system.get_load_average().five / system.get_processors().len() as f64 * 100.,\r
- uptime: std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() - process.start_time()\r
+ uptime: std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() - process.start_time(),\r
+ world_size\r
}\r
)\r
} else {\r