SteamWar/BauSystem2.0
Archiviert
12
0

Update RamUsage to better suit the 5 minute time specified

Dieser Commit ist enthalten in:
yoyosource 2021-05-13 15:40:02 +02:00
Ursprung d3b99bf5ab
Commit 567fbc8425
2 geänderte Dateien mit 17 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -79,5 +79,6 @@ public class AutoShutdownListener implements Listener {
} }
}, 20, 20); }, 20, 20);
} }
System.out.println("LEAVE");
} }
} }

Datei anzeigen

@ -20,23 +20,30 @@
package de.steamwar.bausystem.features.world; package de.steamwar.bausystem.features.world;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import java.lang.management.ManagementFactory; import java.io.*;
import java.util.logging.Level;
@UtilityClass @UtilityClass
public class RamUsage { public class RamUsage {
private File meminfo = new File("/proc/meminfo");
public static double getUsage() { public static double getUsage() {
try { try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(meminfo)))) {
long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize(); String memTotal = bufferedReader.readLine().replaceAll(" +", " ");
long freeMemory = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize(); bufferedReader.readLine();
return (memorySize - freeMemory) / (double) memorySize; String memAvailable = bufferedReader.readLine().replaceAll(" +", " ");
} catch (Throwable throwable) {
Bukkit.getLogger().log(Level.WARNING, throwable.getMessage(), throwable); long memTotalLong = getNumber(memTotal);
long memAvailableLong = getNumber(memAvailable);
return (memTotalLong - memAvailableLong) / (double) memTotalLong;
} catch (IOException e) {
return 1D; return 1D;
} }
} }
private static long getNumber(String s) {
return Long.parseLong(s.split(" ")[1]);
}
} }