From 9ac0a847e5531986bea5a50ae5e9416cb7d88eca Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 20 Jun 2021 23:34:30 +0200 Subject: [PATCH] Add RamUsage.getLoad Signed-off-by: yoyosource --- .../steamwar/bausystem/features/world/RamUsage.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java index 6859cff9..9f5a1fcd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java @@ -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]); }