X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=backend%2Fsrc%2Fminecraft_controller.rs;h=451b0164961d5ca249d6a96cc2eb65e4eabc1f92;hb=2e6831744641c8d8ebeea0a47c933448e8499ddb;hp=8f67d200111f1de90e971bdf3ff524488ff23e2e;hpb=34c1bf4bcb51473466ee9398cb63f0049ddc06a0;p=minecraft_web.git diff --git a/backend/src/minecraft_controller.rs b/backend/src/minecraft_controller.rs index 8f67d20..451b016 100644 --- a/backend/src/minecraft_controller.rs +++ b/backend/src/minecraft_controller.rs @@ -1,7 +1,5 @@ -use sysinfo::{ ProcessExt, SystemExt }; - use std::{ fs, time::SystemTime }; - +use sysinfo::{ ProcessExt, SystemExt }; use chrono::{ DateTime, offset::Local }; #[derive(Clone, Debug)] @@ -11,6 +9,7 @@ pub struct MinecraftExe { uptime: u64, // [s]. world_size: u64, // [B]. active_players: Vec, + version: String, last_backup: Option, } @@ -42,6 +41,10 @@ impl MinecraftExe { } } + pub fn format_version(&self) -> String { + self.version.clone() + } + pub fn format_last_backup(&self) -> String { match self.last_backup { Some(t) => { @@ -74,7 +77,7 @@ fn format_byte_size(bytes: u64, precision: usize) -> String { const MINECRAFT_PROCESS_NAME: &str = "java"; struct StatusFromRcon { - players: Vec, + players: Vec } fn get_status_from_rcon(rcon_password: &str) -> StatusFromRcon { @@ -142,11 +145,12 @@ pub fn get_minecraft_executable_information(world_path: &str, backup_path: &str, Some( MinecraftExe { - memory: process.memory(), - load_average_5min: system.load_average().five / system.processors().len() as f64 * 100., + 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.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: process.cmd()[process.cmd().len() - 2].clone(), // TODO: Extract the version from the .jar filename. last_backup: get_last_backup_datetime(backup_path) } )