SteamWar/BauSystem2.0
Archiviert
12
0

Update RamUsage
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-06-16 19:40:09 +02:00
Ursprung 8a5c3b1647
Commit 567f88c916
2 geänderte Dateien mit 45 neuen und 21 gelöschten Zeilen

Datei anzeigen

@ -36,15 +36,12 @@ public class AFKStopperListener implements Listener {
private int minutesAfk = 0;
public AFKStopperListener() {
Bukkit.getScheduler().runTaskTimerAsynchronously(BauSystem.getInstance(), () -> {
double load = RamUsage.getLoad();
double usage = RamUsage.getUsage();
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
// System.out.println("CPU: " + load + " RAM: " + usage);
if (load < 50.0 && usage < 0.6) {
if (RamUsage.getLoad() < 50.0 && RamUsage.getUsage() < 0.6) {
minutesAfk = 0;
return;
}
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
switch (minutesAfk) {
case 5:
if (Bukkit.getOnlinePlayers().isEmpty()) {
@ -60,7 +57,6 @@ public class AFKStopperListener implements Listener {
default:
minutesAfk++;
}
}, 1);
}, 1200, 1200); //every minute
}

Datei anzeigen

@ -28,7 +28,31 @@ public class RamUsage {
private File meminfo = new File("/proc/meminfo");
private double usage = 0D;
private double load = 0D;
static {
Thread thread = new Thread(() -> {
while (true) {
usage = _getUsage();
load = _getLoad();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
});
thread.setDaemon(true);
thread.setName("RamUsage");
thread.start();
}
public static double getUsage() {
return usage;
}
private static double _getUsage() {
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(meminfo)))) {
String memTotal = bufferedReader.readLine().replaceAll(" +", " ");
bufferedReader.readLine();
@ -43,6 +67,10 @@ public class RamUsage {
}
public static double getLoad() {
return load;
}
private static double _getLoad() {
try {
Process process = new ProcessBuilder("bash", "-c", "cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS=\"\" '{printf \"%.2f\\n\", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'").start();
process.waitFor();