Update RamUsage to better suit the 5 minute time specified
Dieser Commit ist enthalten in:
Ursprung
d3b99bf5ab
Commit
567fbc8425
@ -79,5 +79,6 @@ public class AutoShutdownListener implements Listener {
|
||||
}
|
||||
}, 20, 20);
|
||||
}
|
||||
System.out.println("LEAVE");
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
}
|
||||
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren