SteamWar/BauSystem2.0
Archiviert
12
0

Add RamUsage.getLoad

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-06-20 23:34:30 +02:00
Ursprung c558db31b3
Commit 9ac0a847e5

Datei anzeigen

@ -42,6 +42,19 @@ public class RamUsage {
}
}
public 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();
return Double.parseDouble(new BufferedReader(new InputStreamReader(process.getInputStream())).readLine());
} catch (IOException e) {
return 1D;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return 1D;
}
}
private static long getNumber(String s) {
return Long.parseLong(s.split(" ")[1]);
}