Archiviert
1
0

Fix LoadEvaluation

Dieser Commit ist enthalten in:
yoyosource 2021-06-20 19:02:05 +02:00
Ursprung 85e129ada6
Commit 5aa973d388

Datei anzeigen

@ -42,7 +42,9 @@ public class LoadEvaluation {
public static double getRemoteRamPercentage(String remote) { public static double getRemoteRamPercentage(String remote) {
try { 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(); process.waitFor();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String memTotal = bufferedReader.readLine().replaceAll(" +", " "); String memTotal = bufferedReader.readLine().replaceAll(" +", " ");
@ -64,7 +66,7 @@ public class LoadEvaluation {
try { 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 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(); 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) { } catch (IOException e) {
return 1D; return 1D;
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -75,9 +77,11 @@ public class LoadEvaluation {
public static double getRemoteCPULoad(String remote) { public static double getRemoteCPULoad(String remote) {
try { 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(); 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) { } catch (IOException e) {
return 1D; return 1D;
} catch (InterruptedException e) { } catch (InterruptedException e) {