Merge branch 'master' of gburri.org:minecraft_web into master
authorGreg Burri <greg.burri@gmail.com>
Fri, 8 Apr 2022 15:23:05 +0000 (17:23 +0200)
committerGreg Burri <greg.burri@gmail.com>
Fri, 8 Apr 2022 15:23:05 +0000 (17:23 +0200)
1  2 
backend/src/minecraft_controller.rs

@@@ -1,7 -1,5 +1,5 @@@
- use sysinfo::{ ProcessExt, SystemExt };\r
\r
  use std::{ fs, time::SystemTime };\r
\r
+ use sysinfo::{ ProcessExt, SystemExt };\r
  use chrono::{ DateTime, offset::Local };\r
  \r
  #[derive(Clone, Debug)]\r
@@@ -132,18 -130,20 +130,18 @@@ fn get_last_backup_datetime(backup_path
  pub fn get_minecraft_executable_information(world_path: &str, backup_path: &str, rcon_password: &str) -> Option<MinecraftExe> {\r
      let mut system = sysinfo::System::new_all();\r
      system.refresh_system();\r
 -    let processes = system.get_process_by_name(MINECRAFT_PROCESS_NAME);\r
 +    let mut processes = system.processes_by_name(MINECRAFT_PROCESS_NAME);\r
  \r
      // TODO: find the correct process by checking the correct jar name in parameters.\r
 -    if processes.len() >= 1 {\r
 -        let process = processes.first().unwrap();\r
 -\r
 +    if let Some(process) = processes.next() {\r
          let world_size = match fs_extra::dir::get_size(world_path) { Ok(l) => l, Err(_) => 0u64 };\r
  \r
          let status_from_rcon = get_status_from_rcon(rcon_password);\r
  \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
 +                load_average_5min: system.load_average().five / system.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
                  active_players: status_from_rcon.players,\r