aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me/lucko/spark/common/command
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2019-05-13 12:51:54 +0100
committerLuck <git@lucko.me>2019-05-13 12:51:54 +0100
commitb1bdc139b48517a8bcc88888147f5f1a65b48f93 (patch)
treeeb6aaa3bc5ba38ed39d3ec4b4d943bff38a19f66 /spark-common/src/main/java/me/lucko/spark/common/command
parent6602483b18ff556147094c2e6b816b0898ed698e (diff)
downloadspark-b1bdc139b48517a8bcc88888147f5f1a65b48f93.tar.gz
spark-b1bdc139b48517a8bcc88888147f5f1a65b48f93.tar.bz2
spark-b1bdc139b48517a8bcc88888147f5f1a65b48f93.zip
Change the way CPU monitoring is performed
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/common/command')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java5
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java130
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java4
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java7
4 files changed, 94 insertions, 52 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java
index c51fe2c..edb8537 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java
@@ -68,10 +68,7 @@ public class ActivityLogModule implements CommandModule {
.build()
);
- TextComponent.Builder valueComponent = TextComponent.builder(activity.getDataValue())
- .color(TextColor.WHITE)
- .decoration(TextDecoration.UNDERLINED, true);
-
+ TextComponent.Builder valueComponent = TextComponent.builder(activity.getDataValue(), TextColor.WHITE);
if (activity.getDataType().equals("url")) {
valueComponent.clickEvent(ClickEvent.openUrl(activity.getDataValue()));
}
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java
index f2ae6fc..9c139eb 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java
@@ -54,7 +54,14 @@ public class HealthModule implements CommandModule {
TpsCalculator tpsCalculator = platform.getTpsCalculator();
if (tpsCalculator != null) {
resp.replyPrefixed(TextComponent.of("TPS from last 5s, 10s, 1m, 5m, 15m:"));
- resp.replyPrefixed(TextComponent.builder(" ").append(tpsCalculator.toFormattedComponent()).build());
+ resp.replyPrefixed(TextComponent.builder(" ")
+ .append(formatTps(tpsCalculator.avg5Sec())).append(TextComponent.of(", "))
+ .append(formatTps(tpsCalculator.avg10Sec())).append(TextComponent.of(", "))
+ .append(formatTps(tpsCalculator.avg1Min())).append(TextComponent.of(", "))
+ .append(formatTps(tpsCalculator.avg5Min())).append(TextComponent.of(", "))
+ .append(formatTps(tpsCalculator.avg15Min()))
+ .build()
+ );
} else {
resp.replyPrefixed(TextComponent.of("Not supported!"));
}
@@ -64,6 +71,29 @@ public class HealthModule implements CommandModule {
);
consumer.accept(Command.builder()
+ .aliases("cpu")
+ .executor((platform, sender, resp, arguments) -> {
+ resp.replyPrefixed(TextComponent.of("CPU usage from last 10s, 1m, 15m:"));
+ resp.replyPrefixed(TextComponent.builder(" ")
+ .append(formatCpuUsage(CpuMonitor.systemLoad10SecAvg())).append(TextComponent.of(", "))
+ .append(formatCpuUsage(CpuMonitor.systemLoad1MinAvg())).append(TextComponent.of(", "))
+ .append(formatCpuUsage(CpuMonitor.systemLoad15MinAvg()))
+ .append(TextComponent.of(" (system)", TextColor.DARK_GRAY))
+ .build()
+ );
+ resp.replyPrefixed(TextComponent.builder(" ")
+ .append(formatCpuUsage(CpuMonitor.processLoad10SecAvg())).append(TextComponent.of(", "))
+ .append(formatCpuUsage(CpuMonitor.processLoad1MinAvg())).append(TextComponent.of(", "))
+ .append(formatCpuUsage(CpuMonitor.processLoad15MinAvg()))
+ .append(TextComponent.of(" (process)", TextColor.DARK_GRAY))
+ .build()
+ );
+ })
+ .tabCompleter(Command.TabCompleter.empty())
+ .build()
+ );
+
+ consumer.accept(Command.builder()
.aliases("healthreport", "health", "ht")
.argumentUsage("memory", null)
.executor((platform, sender, resp, arguments) -> {
@@ -80,10 +110,39 @@ public class HealthModule implements CommandModule {
.append(TextComponent.of("TPS from last 5s, 10s, 1m, 5m, 15m:", TextColor.GOLD))
.build()
);
- report.add(TextComponent.builder(" ").append(tpsCalculator.toFormattedComponent()).build());
+ report.add(TextComponent.builder(" ")
+ .append(formatTps(tpsCalculator.avg5Sec())).append(TextComponent.of(", "))
+ .append(formatTps(tpsCalculator.avg10Sec())).append(TextComponent.of(", "))
+ .append(formatTps(tpsCalculator.avg1Min())).append(TextComponent.of(", "))
+ .append(formatTps(tpsCalculator.avg5Min())).append(TextComponent.of(", "))
+ .append(formatTps(tpsCalculator.avg15Min()))
+ .build()
+ );
report.add(TextComponent.empty());
}
+ report.add(TextComponent.builder("")
+ .append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build())
+ .append(TextComponent.space())
+ .append(TextComponent.of("CPU usage from last 10s, 1m, 15m:", TextColor.GOLD))
+ .build()
+ );
+ report.add(TextComponent.builder(" ")
+ .append(formatCpuUsage(CpuMonitor.systemLoad10SecAvg())).append(TextComponent.of(", "))
+ .append(formatCpuUsage(CpuMonitor.systemLoad1MinAvg())).append(TextComponent.of(", "))
+ .append(formatCpuUsage(CpuMonitor.systemLoad15MinAvg()))
+ .append(TextComponent.of(" (system)", TextColor.DARK_GRAY))
+ .build()
+ );
+ report.add(TextComponent.builder(" ")
+ .append(formatCpuUsage(CpuMonitor.processLoad10SecAvg())).append(TextComponent.of(", "))
+ .append(formatCpuUsage(CpuMonitor.processLoad1MinAvg())).append(TextComponent.of(", "))
+ .append(formatCpuUsage(CpuMonitor.processLoad15MinAvg()))
+ .append(TextComponent.of(" (process)", TextColor.DARK_GRAY))
+ .build()
+ );
+ report.add(TextComponent.empty());
+
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
MemoryUsage heapUsage = memoryMXBean.getHeapMemoryUsage();
report.add(TextComponent.builder("")
@@ -168,37 +227,6 @@ public class HealthModule implements CommandModule {
}
}
- double systemCpuLoad = CpuMonitor.getSystemCpuLoad();
- double processCpuLoad = CpuMonitor.getProcessCpuLoad();
-
- if (systemCpuLoad >= 0 || processCpuLoad >= 0) {
- report.add(TextComponent.builder("")
- .append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build())
- .append(TextComponent.space())
- .append(TextComponent.of("CPU usage:", TextColor.GOLD))
- .build()
- );
-
- if (systemCpuLoad >= 0) {
- report.add(TextComponent.builder(" ")
- .append(TextComponent.of("System: ", TextColor.GRAY))
- .append(TextComponent.of(percent(systemCpuLoad, 1.0d), TextColor.GREEN))
- .build()
- );
- report.add(TextComponent.builder(" ").append(generateCpuUsageDiagram(systemCpuLoad, 40)).build());
- report.add(TextComponent.empty());
- }
- if (processCpuLoad >= 0) {
- report.add(TextComponent.builder(" ")
- .append(TextComponent.of("Process: ", TextColor.GRAY))
- .append(TextComponent.of(percent(processCpuLoad, 1.0d), TextColor.GREEN))
- .build()
- );
- report.add(TextComponent.builder(" ").append(generateCpuUsageDiagram(processCpuLoad, 40)).build());
- report.add(TextComponent.empty());
- }
- }
-
try {
FileStore fileStore = Files.getFileStore(Paths.get("."));
long totalSpace = fileStore.getTotalSpace();
@@ -242,6 +270,32 @@ public class HealthModule implements CommandModule {
return (int) percent + "%";
}
+ private static TextComponent formatTps(double tps) {
+ TextColor color;
+ if (tps > 18.0) {
+ color = TextColor.GREEN;
+ } else if (tps > 16.0) {
+ color = TextColor.YELLOW;
+ } else {
+ color = TextColor.RED;
+ }
+
+ return TextComponent.of( (tps > 20.0 ? "*" : "") + Math.min(Math.round(tps * 100.0) / 100.0, 20.0), color);
+ }
+
+ private static TextComponent formatCpuUsage(double usage) {
+ TextColor color;
+ if (usage > 0.9) {
+ color = TextColor.RED;
+ } else if (usage > 0.65) {
+ color = TextColor.YELLOW;
+ } else {
+ color = TextColor.GREEN;
+ }
+
+ return TextComponent.of(percent(usage, 1d), color);
+ }
+
private static TextComponent generateMemoryUsageDiagram(MemoryUsage usage, int length) {
double used = usage.getUsed();
double committed = usage.getCommitted();
@@ -300,16 +354,6 @@ public class HealthModule implements CommandModule {
.build();
}
- private static TextComponent generateCpuUsageDiagram(double usage, int length) {
- int usedChars = (int) ((usage * length));
- String line = Strings.repeat("/", usedChars) + Strings.repeat(" ", length - usedChars);
- return TextComponent.builder("")
- .append(TextComponent.of("[", TextColor.DARK_GRAY))
- .append(TextComponent.of(line, TextColor.GRAY))
- .append(TextComponent.of("]", TextColor.DARK_GRAY))
- .build();
- }
-
private static TextComponent generateDiskUsageDiagram(double used, double max, int length) {
int usedChars = (int) ((used * length) / max);
String line = Strings.repeat("/", usedChars) + Strings.repeat(" ", length - usedChars);
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java
index 42c03d0..f5854f0 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java
@@ -65,7 +65,7 @@ public class MemoryModule implements CommandModule {
return;
}
- byte[] output = heapDump.formCompressedDataPayload();
+ byte[] output = heapDump.formCompressedDataPayload(sender);
try {
String key = SparkPlatform.BYTEBIN_CLIENT.postContent(output, JSON_TYPE, false).key();
String url = SparkPlatform.VIEWER_URL + key;
@@ -120,7 +120,7 @@ public class MemoryModule implements CommandModule {
}
resp.broadcastPrefixed(TextComponent.builder("Heap dump written to: ", TextColor.GOLD)
- .append(TextComponent.of(file.toString(), TextColor.DARK_GRAY))
+ .append(TextComponent.of(file.toString(), TextColor.GRAY))
.build()
);
platform.getActivityLog().addToLog(Activity.fileActivity(sender, System.currentTimeMillis(), "Heap dump", file.toString()));
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java
index 4ea6144..4b7baae 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java
@@ -228,8 +228,9 @@ public class SamplerModule implements CommandModule {
return Collections.emptyList();
}
- List<String> opts = new ArrayList<>(Arrays.asList("--timeout", "--regex", "--combine-all",
- "--not-combined", "--interval", "--only-ticks-over", "--include-line-numbers"));
+ List<String> opts = new ArrayList<>(Arrays.asList("--info", "--stop", "--cancel",
+ "--timeout", "--regex", "--combine-all", "--not-combined", "--interval",
+ "--only-ticks-over", "--include-line-numbers"));
opts.removeAll(arguments);
opts.add("--thread"); // allowed multiple times
@@ -243,7 +244,7 @@ public class SamplerModule implements CommandModule {
private void handleUpload(SparkPlatform platform, CommandResponseHandler resp, Sampler sampler) {
platform.getPlugin().runAsync(() -> {
- byte[] output = sampler.formCompressedDataPayload();
+ byte[] output = sampler.formCompressedDataPayload(resp.sender());
try {
String key = SparkPlatform.BYTEBIN_CLIENT.postContent(output, JSON_TYPE, false).key();
String url = SparkPlatform.VIEWER_URL + key;