From 5aa973d3889cd20689ab58be6e1bdf459a843315 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 20 Jun 2021 19:02:05 +0200 Subject: [PATCH] Fix LoadEvaluation --- src/de/steamwar/bungeecore/LoadEvaluation.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/LoadEvaluation.java b/src/de/steamwar/bungeecore/LoadEvaluation.java index d4acab0..0732d75 100644 --- a/src/de/steamwar/bungeecore/LoadEvaluation.java +++ b/src/de/steamwar/bungeecore/LoadEvaluation.java @@ -42,7 +42,9 @@ public class LoadEvaluation { public static double getRemoteRamPercentage(String remote) { try { - Process process = new ProcessBuilder("ssh " + remote + " cat /proc/meminfo").start(); + // Attention: + // memInfo.sh needs to contain: cat /proc/meminfo + Process process = new ProcessBuilder("ssh", remote, "\"./memInfo.sh\"").start(); process.waitFor(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); String memTotal = bufferedReader.readLine().replaceAll(" +", " "); @@ -64,7 +66,7 @@ public class LoadEvaluation { try { Process process = new ProcessBuilder("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()); + return Double.parseDouble(new BufferedReader(new InputStreamReader(process.getInputStream())).readLine()) / 100.0; } catch (IOException e) { return 1D; } catch (InterruptedException e) { @@ -75,9 +77,11 @@ public class LoadEvaluation { public static double getRemoteCPULoad(String remote) { try { - Process process = new ProcessBuilder("ssh " + remote + " 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(); + // Attention: + // cpuLoad.sh needs to contain: 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)}' + Process process = new ProcessBuilder("ssh", remote, "\"./cpuLoad.sh\"").start(); process.waitFor(); - return Double.parseDouble(new BufferedReader(new InputStreamReader(process.getInputStream())).readLine()); + return Double.parseDouble(new BufferedReader(new InputStreamReader(process.getInputStream())).readLine()) / 100.0; } catch (IOException e) { return 1D; } catch (InterruptedException e) {