diff options
author | Luck <git@lucko.me> | 2020-02-04 00:49:40 +0000 |
---|---|---|
committer | Luck <git@lucko.me> | 2020-02-04 00:49:40 +0000 |
commit | e02d52ce8d45550a4d77f11971e31cf0732e5f0c (patch) | |
tree | cfcfb2850ff6b279276e43233e5e1acf82993a98 /spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder | |
parent | d15a12788ddc8aba09f49003fcef55b927850de3 (diff) | |
download | spark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.tar.gz spark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.tar.bz2 spark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.zip |
Monitor average tick durations & report them in /spark tps
Diffstat (limited to 'spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder')
-rw-r--r-- | spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java index d94ce95..0f57149 100644 --- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java +++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java @@ -23,7 +23,7 @@ package me.lucko.spark.bukkit.placeholder; import me.lucko.spark.common.SparkPlatform; import me.lucko.spark.common.command.modules.HealthModule; import me.lucko.spark.common.monitor.cpu.CpuMonitor; -import me.lucko.spark.common.monitor.tick.TpsCalculator; +import me.lucko.spark.common.monitor.tick.TickStatistics; import net.kyori.text.TextComponent; import net.kyori.text.serializer.legacy.LegacyComponentSerializer; @@ -32,37 +32,59 @@ enum SparkPlaceholderProvider { public static TextComponent respondComponent(SparkPlatform platform, String placeholder) { if (placeholder.startsWith("tps")) { - TpsCalculator tpsCalculator = platform.getTpsCalculator(); - if (tpsCalculator == null) { + TickStatistics tickStatistics = platform.getTickStatistics(); + if (tickStatistics == null) { return null; } switch (placeholder) { case "tps": - return TextComponent.builder(" ") - .append(HealthModule.formatTps(tpsCalculator.avg5Sec())).append(TextComponent.of(", ")) - .append(HealthModule.formatTps(tpsCalculator.avg10Sec())).append(TextComponent.of(", ")) - .append(HealthModule.formatTps(tpsCalculator.avg1Min())).append(TextComponent.of(", ")) - .append(HealthModule.formatTps(tpsCalculator.avg5Min())).append(TextComponent.of(", ")) - .append(HealthModule.formatTps(tpsCalculator.avg15Min())) + return TextComponent.builder("") + .append(HealthModule.formatTps(tickStatistics.tps5Sec())).append(TextComponent.of(", ")) + .append(HealthModule.formatTps(tickStatistics.tps10Sec())).append(TextComponent.of(", ")) + .append(HealthModule.formatTps(tickStatistics.tps1Min())).append(TextComponent.of(", ")) + .append(HealthModule.formatTps(tickStatistics.tps5Min())).append(TextComponent.of(", ")) + .append(HealthModule.formatTps(tickStatistics.tps15Min())) .build(); case "tps_5s": - return HealthModule.formatTps(tpsCalculator.avg5Sec()); + return HealthModule.formatTps(tickStatistics.tps5Sec()); case "tps_10s": - return HealthModule.formatTps(tpsCalculator.avg10Sec()); + return HealthModule.formatTps(tickStatistics.tps10Sec()); case "tps_1m": - return HealthModule.formatTps(tpsCalculator.avg1Min()); + return HealthModule.formatTps(tickStatistics.tps1Min()); case "tps_5m": - return HealthModule.formatTps(tpsCalculator.avg5Min()); + return HealthModule.formatTps(tickStatistics.tps5Min()); case "tps_15m": - return HealthModule.formatTps(tpsCalculator.avg15Min()); + return HealthModule.formatTps(tickStatistics.tps15Min()); + } + } + + if (placeholder.startsWith("tickduration")) { + TickStatistics tickStatistics = platform.getTickStatistics(); + if (tickStatistics == null || !tickStatistics.isDurationSupported()) { + return null; + } + + switch (placeholder) { + case "tickduration": + return TextComponent.builder("") + .append(HealthModule.formatTickDurations(tickStatistics.duration5Sec())).append(TextComponent.of(", ")) + .append(HealthModule.formatTickDurations(tickStatistics.duration10Sec())).append(TextComponent.of(", ")) + .append(HealthModule.formatTickDurations(tickStatistics.duration1Min())) + .build(); + case "tickduration_5s": + return HealthModule.formatTickDurations(tickStatistics.duration5Sec()); + case "tickduration_10s": + return HealthModule.formatTickDurations(tickStatistics.duration10Sec()); + case "tickduration_1m": + return HealthModule.formatTickDurations(tickStatistics.duration1Min()); } } if (placeholder.startsWith("cpu")) { switch (placeholder) { case "cpu_system": - return TextComponent.builder(" ") + return TextComponent.builder("") .append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad10SecAvg())).append(TextComponent.of(", ")) .append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad1MinAvg())).append(TextComponent.of(", ")) .append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad15MinAvg())) @@ -74,7 +96,7 @@ enum SparkPlaceholderProvider { case "cpu_system_15m": return HealthModule.formatCpuUsage(CpuMonitor.systemLoad15MinAvg()); case "cpu_process": - return TextComponent.builder(" ") + return TextComponent.builder("") .append(HealthModule.formatCpuUsage(CpuMonitor.processLoad10SecAvg())).append(TextComponent.of(", ")) .append(HealthModule.formatCpuUsage(CpuMonitor.processLoad1MinAvg())).append(TextComponent.of(", ")) .append(HealthModule.formatCpuUsage(CpuMonitor.processLoad15MinAvg())) |