X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=backend%2Fsrc%2Fminecraft_controller.rs;h=4a9d754f9d13b4db800e8bb7f0af1e0570c4835b;hb=HEAD;hp=545e8c228a3ded8038ea12653ca12f31051066f8;hpb=3c7277e35a204d40d9e72794503a68530fcec682;p=minecraft_web.git diff --git a/backend/src/minecraft_controller.rs b/backend/src/minecraft_controller.rs index 545e8c2..4a9d754 100644 --- a/backend/src/minecraft_controller.rs +++ b/backend/src/minecraft_controller.rs @@ -4,7 +4,7 @@ use chrono::{ DateTime, offset::Local }; #[derive(Clone, Debug)] pub struct MinecraftExe { - memory: u64, // [kB]. + memory: u64, // [B]. load_average_5min: f64, // [%]. uptime: u64, // [s]. world_size: u64, // [B]. @@ -15,7 +15,7 @@ pub struct MinecraftExe { impl MinecraftExe { pub fn format_memory(&self) -> String { - format_byte_size(self.memory * 1024, 2) + format_byte_size(self.memory, 2) } pub fn format_load_average(&self) -> String { @@ -77,8 +77,7 @@ fn format_byte_size(bytes: u64, precision: usize) -> String { const MINECRAFT_PROCESS_NAME: &str = "java"; struct StatusFromRcon { - players: Vec, - version: String, + players: Vec } fn get_status_from_rcon(rcon_password: &str) -> StatusFromRcon { @@ -104,20 +103,12 @@ fn get_status_from_rcon(rcon_password: &str) -> StatusFromRcon { println!("Error from 'list' command"); Vec::new() }, - }, - version: - match client.send_command("list".to_string()) { - Ok(resp) => resp.body, - Err(_e) => { - println!("Error from 'version' command"); - String::new() - } } } }, Err(_e) => { println!("Authentication error"); - StatusFromRcon { players: Vec::new(), version: String::new() } + StatusFromRcon { players: Vec::new() } }, }; @@ -155,11 +146,11 @@ pub fn get_minecraft_executable_information(world_path: &str, backup_path: &str, Some( MinecraftExe { memory: process.memory() / 3, // Because the Java garbage collector ZGC reports three times more the real memory usage: https://stackoverflow.com/a/62934057/212675 - load_average_5min: system.load_average().five / system.processors().len() as f64 * 100., + load_average_5min: system.load_average().five / system.cpus().len() as f64 * 100., uptime: std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() - process.start_time(), world_size, active_players: status_from_rcon.players, - version: status_from_rcon.version, + version: process.cmd()[process.cmd().len() - 2].clone(), // TODO: Extract the version from the .jar filename. last_backup: get_last_backup_datetime(backup_path) } )