Adjust the reported memory from the java process.
[minecraft_web.git] / backend / src / minecraft_controller.rs
index 163008a..7af13dd 100644 (file)
@@ -86,14 +86,16 @@ fn get_status_from_rcon(rcon_password: &str) -> StatusFromRcon {
                 StatusFromRcon {\r
                     players:\r
                         match client.send_command("list".to_string()) {\r
-                            Ok(resp) => {\r
-                                resp.body\r
-                                    .split('\n')\r
-                                    .skip(1)\r
-                                    .filter(|n| !n.is_empty())\r
-                                    .map(|n| n.to_string())\r
-                                    .collect()\r
-                            },\r
+                            Ok(resp) =>\r
+                                match resp.body.find(':') {\r
+                                    Some(i) if i < resp.body.len() -1 =>\r
+                                        resp.body[i + 1..resp.body.len()]\r
+                                            .split(',')\r
+                                            .map(|nick| nick.trim().to_string())\r
+                                            .filter(|nick| !nick.is_empty())\r
+                                            .collect(),\r
+                                    _ => Vec::new()\r
+                                },\r
                             Err(_e) => {\r
                                 println!("Error from 'list' command");\r
                                 Vec::new()\r
@@ -142,7 +144,7 @@ pub fn get_minecraft_executable_information(world_path: &str, backup_path: &str,
 \r
         Some(\r
             MinecraftExe {\r
-                memory: process.memory(),\r
+                memory: process.memory() / 3, // Because the Java garbage collector ZGC reports three times more the real memory usage: https://stackoverflow.com/a/62934057/212675\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
                 world_size,\r