diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/TPSPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/TPSPart.java index 849c390b3..3bdd61928 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/TPSPart.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/analysis/TPSPart.java @@ -1,13 +1,15 @@ package main.java.com.djrapitops.plan.data.analysis; import com.djrapitops.plugin.api.TimeAmount; -import java.util.List; import main.java.com.djrapitops.plan.data.TPS; +import main.java.com.djrapitops.plan.ui.html.graphs.CPUGraphCreator; import main.java.com.djrapitops.plan.ui.html.graphs.TPSGraphCreator; import main.java.com.djrapitops.plan.utilities.FormatUtils; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; +import java.util.List; + /** * Part responsible for all TPS related analysis. * @@ -15,7 +17,7 @@ import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; * * Placeholder values can be retrieved using the get method. * - * Contains following place-holders: tpsscatterday, tpsscatterweek, averagetps, + * Contains following place-holders: tpsscatterday, tpsscatterweek, cpuscatterday, cpuscatterweek, averagetps, * averagetpsday * * @author Rsl1122 @@ -37,10 +39,15 @@ public class TPSPart extends RawData { String tpsScatterDay = TPSGraphCreator.buildScatterDataStringTPS(day, TimeAmount.DAY.ms()); String tpsScatterWeek = TPSGraphCreator.buildScatterDataStringTPS(week, TimeAmount.WEEK.ms()); + String cpuScatterDay = CPUGraphCreator.buildScatterDataString(day, TimeAmount.DAY.ms()); + String cpuScatterWeek = CPUGraphCreator.buildScatterDataString(week, TimeAmount.WEEK.ms()); addValue("tpsscatterday", tpsScatterDay); addValue("tpsscatterweek", tpsScatterWeek); + addValue("cpuscatterday", cpuScatterDay); + addValue("cpuscatterweek", cpuScatterWeek); + double averageTPSweek = MathUtils.averageDouble(week.stream().map(TPS::getTps)); double averageTPSday = MathUtils.averageDouble(day.stream().map(TPS::getTps)); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/TPSCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/TPSCountTimer.java index ce848b8d2..2fa7b4b5a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/TPSCountTimer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/TPSCountTimer.java @@ -65,8 +65,11 @@ public class TPSCountTimer extends AbsRunnable { */ private TPS calculateTPS(long diff, long now) { OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); - int availableProcessors = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors(); - final double averageCPUUsage = MathUtils.round(operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0); + int availableProcessors = operatingSystemMXBean.getAvailableProcessors(); + double averageCPUUsage = MathUtils.round(operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0); + if (averageCPUUsage < 0) { // If Unavailable, getSystemLoadAverage() returns -1 + averageCPUUsage = -1; + } int playersOnline = plugin.getServer().getOnlinePlayers().size(); diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/RecentPlayersButtonsCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/RecentPlayersButtonsCreator.java index 8e4994664..c3144f020 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/RecentPlayersButtonsCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/RecentPlayersButtonsCreator.java @@ -23,7 +23,7 @@ public class RecentPlayersButtonsCreator { for (int i = 0; i < names.size(); i++) { if (i < limit) { String name = names.get(i); - html.append(Html.BUTTON.parse(HtmlUtils.getInspectUrl(name), name)); + html.append(Html.BUTTON.parse(HtmlUtils.getRelativeInspectUrl(name), name)); html.append(" "); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/CPUGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/CPUGraphCreator.java new file mode 100644 index 000000000..9743b0670 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/CPUGraphCreator.java @@ -0,0 +1,20 @@ +package main.java.com.djrapitops.plan.ui.html.graphs; + +import main.java.com.djrapitops.plan.data.TPS; +import main.java.com.djrapitops.plan.utilities.FormatUtils; +import main.java.com.djrapitops.plan.utilities.MiscUtils; +import main.java.com.djrapitops.plan.utilities.analysis.Point; + +import java.util.List; +import java.util.stream.Collectors; + +public class CPUGraphCreator { + public static String buildScatterDataString(List tpsData, long scale) { + long now = MiscUtils.getTime(); + List points = tpsData.stream() + .filter(tps -> tps.getDate() >= now - scale) + .map(tps -> new Point(tps.getDate(), Double.parseDouble(FormatUtils.cutDecimals(tps.getCPUUsage()).replace(",", ".")))) + .collect(Collectors.toList()); + return ScatterGraphCreator.scatterGraph(points, true); + } +} diff --git a/Plan/src/main/resources/analysis.html b/Plan/src/main/resources/analysis.html index b46986fdb..06f435d1f 100644 --- a/Plan/src/main/resources/analysis.html +++ b/Plan/src/main/resources/analysis.html @@ -688,6 +688,9 @@ +
+ +
@@ -712,6 +715,10 @@
+
+ +
+

If CPU Graph displays '-1' CPU usage is not available for this platform.

@@ -1302,6 +1309,131 @@ }); + +