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);
}
System.out.println("LEAVE");
}
}

Datei anzeigen

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