SteamWar/BungeeCore
Archiviert
13
2

Add StatCommand

Fix LoadEvaluation
Dieser Commit ist enthalten in:
yoyosource 2021-06-20 21:36:58 +02:00
Ursprung ddf06701e8
Commit f6a4c343a5
4 geänderte Dateien mit 53 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -121,6 +121,7 @@ public class BungeeCore extends Plugin {
new UnIgnoreCommand();
new PollresultCommand();
new ResourcereloadCommand();
new StatCommand();
if(!EVENT_MODE){
new WebregisterCommand();

Datei anzeigen

@ -64,12 +64,14 @@ public class LoadEvaluation {
public static double getCPULoad() {
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("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()) / 100.0;
} catch (IOException e) {
e.printStackTrace();
return 1D;
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
return 1D;
}

Datei anzeigen

@ -0,0 +1,48 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.LoadEvaluation;
import de.steamwar.bungeecore.Message;
import net.md_5.bungee.api.CommandSender;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class StatCommand extends BasicCommand {
public StatCommand() {
super("stat", "bungeecore.softreload","stats");
}
@Override
public void execute(CommandSender sender, String[] args) {
try {
Process process = new ProcessBuilder("ps", "x").start();
process.waitFor();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
Map<String, Integer> serverCounts = new HashMap<>();
bufferedReader.lines().forEach(s -> {
if (!s.contains("--port") || s.contains("grep")) {
return;
}
String server = "SW";
if (s.contains("ssh -L")) {
server = s.substring(s.indexOf("ssh -L") + 6).split(" ")[2];
}
serverCounts.put(server, serverCounts.computeIfAbsent(server, s1 -> 0) + 1);
});
serverCounts.forEach((s, integer) -> {
if (s.equals("SW")) {
Message.send("STAT_SERVER", sender, s, LoadEvaluation.getRamPercentage(), LoadEvaluation.getCPULoad(), integer);
} else {
Message.send("STAT_SERVER", sender, s.toUpperCase(), LoadEvaluation.getRemoteRamPercentage(s), LoadEvaluation.getRemoteCPULoad(s), integer);
}
});
} catch (Exception e) {
throw new SecurityException(e.getMessage(), e);
}
}
}

Datei anzeigen

@ -104,6 +104,7 @@ MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War
#Various commands
ALERT=§f{0}
STAT_SERVER=§7Server §f{0} - §7Ram §f{1} §7CPU §f{2} §7Server Count §f{3}
#Ban&Mute-Command
BAN_TEAM_BANNED={0} §c{1} wurde von {2} {3} gebannt. §f§lGrund: §f{4}