9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-21 15:59:28 +00:00
Files
Gale/patches/server/0006-Gale-metrics.patch
Dreeam d95dc9d8a0 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@2df5bba Log throwable when failing to save chunk/poi/entity data
PaperMC/Paper@44c3dd0 fix exact choice shapeless recipes (#10973)
2024-07-18 06:44:23 +08:00

334 lines
17 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Mon, 26 Dec 2022 13:47:57 +0100
Subject: [PATCH] Gale metrics
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkTaskScheduler.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkTaskScheduler.java
index b1456c1ddf24b625c6caf41a9379d8c011e1c36c..be7a4e2fd8823925847949d33358d64d464ec79f 100644
--- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkTaskScheduler.java
+++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkTaskScheduler.java
@@ -65,7 +65,7 @@ public final class ChunkTaskScheduler {
private static final Logger LOGGER = LogUtils.getClassLogger();
- static int newChunkSystemIOThreads;
+ public static int newChunkSystemIOThreads; // Gale - metrics - chunk system IO threads - package-private -> public
static int newChunkSystemGenParallelism;
static int newChunkSystemGenPopulationParallelism;
static int newChunkSystemLoadParallelism;
diff --git a/src/main/java/com/destroystokyo/paper/Metrics.java b/src/main/java/com/destroystokyo/paper/Metrics.java
index 4b002e8b75d117b726b0de274a76d3596fce015b..7e1405d5e2b847b28b07cb94fcbf5dec78706e34 100644
--- a/src/main/java/com/destroystokyo/paper/Metrics.java
+++ b/src/main/java/com/destroystokyo/paper/Metrics.java
@@ -593,7 +593,7 @@ public class Metrics {
boolean logFailedRequests = config.getBoolean("logFailedRequests", false);
// Only start Metrics, if it's enabled in the config
if (config.getBoolean("enabled", true)) {
- Metrics metrics = new Metrics("Paper", serverUUID, logFailedRequests, Bukkit.getLogger());
+ Metrics metrics = new Metrics("Gale", serverUUID, logFailedRequests, Bukkit.getLogger()); // Gale - branding changes - metrics
metrics.addCustomChart(new Metrics.SimplePie("minecraft_version", () -> {
String minecraftVersion = Bukkit.getVersion();
@@ -603,20 +603,20 @@ public class Metrics {
metrics.addCustomChart(new Metrics.SingleLineChart("players", () -> Bukkit.getOnlinePlayers().size()));
metrics.addCustomChart(new Metrics.SimplePie("online_mode", () -> Bukkit.getOnlineMode() ? "online" : "offline"));
- final String paperVersion;
+ final String galeVersion; // Gale - branding changes - metrics
final String implVersion = org.bukkit.craftbukkit.Main.class.getPackage().getImplementationVersion();
if (implVersion != null) {
final String buildOrHash = implVersion.substring(implVersion.lastIndexOf('-') + 1);
- paperVersion = "git-Paper-%s-%s".formatted(Bukkit.getServer().getMinecraftVersion(), buildOrHash);
+ galeVersion = "git-Gale-%s-%s".formatted(Bukkit.getServer().getMinecraftVersion(), buildOrHash); // Gale - branding changes - metrics
} else {
- paperVersion = "unknown";
+ galeVersion = "unknown"; // Gale - branding changes - metrics
}
- metrics.addCustomChart(new Metrics.SimplePie("paper_version", () -> paperVersion));
+ metrics.addCustomChart(new Metrics.SimplePie("gale_version", () -> galeVersion)); // Gale - branding changes - metrics
metrics.addCustomChart(new Metrics.DrilldownPie("java_version", () -> {
- Map<String, Map<String, Integer>> map = new HashMap<>();
+ Map<String, Map<String, Integer>> map = new HashMap<>(2); // Gale - metrics - reduce HashMap capacity
String javaVersion = System.getProperty("java.version");
- Map<String, Integer> entry = new HashMap<>();
+ Map<String, Integer> entry = new HashMap<>(2); // Gale - metrics - reduce HashMap capacity
entry.put(javaVersion, 1);
// http://openjdk.java.net/jeps/223
@@ -645,7 +645,7 @@ public class Metrics {
}));
metrics.addCustomChart(new Metrics.DrilldownPie("legacy_plugins", () -> {
- Map<String, Map<String, Integer>> map = new HashMap<>();
+ Map<String, Map<String, Integer>> map = new HashMap<>(2); // Gale - metrics - reduce HashMap capacity
// count legacy plugins
int legacy = 0;
@@ -656,7 +656,7 @@ public class Metrics {
}
// insert real value as lower dimension
- Map<String, Integer> entry = new HashMap<>();
+ Map<String, Integer> entry = new HashMap<>(2); // Gale - metrics - reduce HashMap capacity
entry.put(String.valueOf(legacy), 1);
// create buckets as higher dimension
@@ -676,6 +676,253 @@ public class Metrics {
return map;
}));
+
+ // Gale start - metrics - proxy
+ metrics.addCustomChart(new Metrics.DrilldownPie("proxy", () -> {
+ String type;
+ boolean onlineMode;
+ var proxiesConfig = io.papermc.paper.configuration.GlobalConfiguration.get().proxies;
+ if (proxiesConfig.velocity.enabled) {
+ type = "Velocity";
+ onlineMode = proxiesConfig.velocity.onlineMode;
+ } else if (org.spigotmc.SpigotConfig.bungee) {
+ type = "BungeeCord";
+ onlineMode = proxiesConfig.bungeeCord.onlineMode;
+ } else {
+ type = "none";
+ onlineMode = Bukkit.getOnlineMode();
+ }
+
+ Map<String, Map<String, Integer>> map = new HashMap<>(2);
+
+ // insert type and online mode as lower dimension
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put(type + " (" + (onlineMode ? "online" : "offline") + ")", 1);
+
+ // create type as higher dimension
+ map.put(type, entry);
+
+ return map;
+ }));
+ // Gale end - metrics - proxy
+
+ // Gale start - metrics - Java VM
+ Map<String, Map<String, Integer>> javaVirtualMachineMap = new HashMap<>(2);
+ {
+ Map<String, Integer> entry = new HashMap<>(2);
+ String vmVendor = null;
+ try {
+ vmVendor = System.getProperty("java.vm.vendor");
+ } catch (Exception ignored) {}
+ entry.put(vmVendor == null ? "Unknown" : vmVendor, 1);
+ String vmName = null;
+ try {
+ vmName = System.getProperty("java.vm.name");
+ } catch (Exception ignored) {}
+ javaVirtualMachineMap.put(vmName == null ? "Unknown" : vmName, entry);
+ }
+ metrics.addCustomChart(new Metrics.DrilldownPie("java_virtual_machine", () -> javaVirtualMachineMap));
+ // Gale end - metrics - Java VM
+
+ // Gale start - metrics - per-server player count
+ metrics.addCustomChart(new Metrics.DrilldownPie("per_server_player_count", () -> {
+ Map<String, Map<String, Integer>> map = new HashMap<>(2);
+
+ // count players
+ int playerCount = Bukkit.getOnlinePlayers().size();
+
+ // insert real value as lower dimension
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put(String.valueOf(playerCount), 1);
+
+ // create buckets as higher dimension
+ if (playerCount <= 5) {
+ map.put(String.valueOf(playerCount), entry);
+ } else if (playerCount > 1000) {
+ map.put("> 1000", entry);
+ } else {
+ int divisor;
+ if (playerCount <= 50) {
+ divisor = 5;
+ } else if (playerCount <= 100) {
+ divisor = 10;
+ } else if (playerCount <= 250) {
+ divisor = 25;
+ } else if (playerCount <= 500) {
+ divisor = 50;
+ } else {
+ divisor = 100;
+ }
+ int start = (playerCount - 1) / divisor * divisor + 1;
+ int end = start + divisor - 1;
+ map.put(start + "-" + end, entry);
+ }
+
+ return map;
+ }));
+ // Gale end - metrics - per-server player count
+
+ // Gale start - metrics - plugin count
+ metrics.addCustomChart(new Metrics.DrilldownPie("plugin_count", () -> {
+ Map<String, Map<String, Integer>> map = new HashMap<>(2);
+
+ // count plugins
+ int pluginCount = Bukkit.getPluginManager().getPlugins().length;
+
+ // insert real value as lower dimension
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put(String.valueOf(pluginCount), 1);
+
+ // create buckets as higher dimension
+ if (pluginCount <= 5) {
+ map.put(String.valueOf(pluginCount), entry);
+ } else if (pluginCount > 1000) {
+ map.put("> 1000", entry);
+ } else {
+ int divisor;
+ if (pluginCount <= 50) {
+ divisor = 5;
+ } else if (pluginCount <= 100) {
+ divisor = 10;
+ } else if (pluginCount <= 250) {
+ divisor = 25;
+ } else if (pluginCount <= 500) {
+ divisor = 50;
+ } else {
+ divisor = 100;
+ }
+ int start = (pluginCount - 1) / divisor * divisor + 1;
+ int end = start + divisor - 1;
+ map.put(start + "-" + end, entry);
+ }
+
+ return map;
+ }));
+ // Gale end - metrics - plugin count
+
+ // Gale start - metrics - netty threads
+ metrics.addCustomChart(new Metrics.SimplePie("netty_thread_count", () -> {
+ // Try to get the number of Netty threads from the system property
+ try {
+ return System.getProperty("io.netty.eventLoopThreads");
+ } catch (Exception ignored) {}
+ // Otherwise, we fall back to nothing currently (reading from the Spigot configuration causes a re-read which is undesirable)
+ return null;
+ }));
+ // Gale end - metrics - netty threads
+
+ metrics.addCustomChart(new Metrics.SimplePie("chunk_system_io_thread_count", () -> String.valueOf(ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkTaskScheduler.newChunkSystemIOThreads))); // Gale - metrics - chunk system IO threads
+
+ // Gale start - metrics - physical cores
+ metrics.addCustomChart(new Metrics.SimplePie("physical_core_count", () -> {
+ try {
+ int physicalProcessorCount = new oshi.SystemInfo().getHardware().getProcessor().getPhysicalProcessorCount();
+ if (physicalProcessorCount > 0) {
+ return String.valueOf(physicalProcessorCount);
+ }
+ } catch (Exception ignored) {}
+ return null;
+ }));
+ // Gale end - metrics - physical cores
+
+ // Gale start - metrics - processor frequency
+ metrics.addCustomChart(new Metrics.DrilldownPie("processor_frequency", () -> {
+ try {
+ long processorFrequency = new oshi.SystemInfo().getHardware().getProcessor().getProcessorIdentifier().getVendorFreq();
+ if (processorFrequency > 0) {
+
+ Map<String, Map<String, Integer>> map = new HashMap<>(2);
+
+ // use MHz as lower dimension
+ var flooredMHz = processorFrequency / 1_000_000L;
+ Map<String, Integer> entry = new HashMap<>(2);
+ if (flooredMHz < 1) {
+ entry.put("< 1 MHz", 1);
+ } else if (flooredMHz < 1000) {
+ entry.put(flooredMHz + " MHz", 1);
+ } else {
+ // Add a comma
+ StringBuilder flooredMHzAfterComma = new StringBuilder(String.valueOf(flooredMHz % 1000));
+ while (flooredMHzAfterComma.length() < 3) {
+ flooredMHzAfterComma.insert(0, "0");
+ }
+ entry.put((flooredMHz / 1000) + "," + flooredMHzAfterComma + " MHz", 1);
+ }
+
+ // use tenth of GHz as higher dimension
+ long flooredTenthGHz = processorFrequency / 100_000_000L;
+ if (flooredTenthGHz < 1) {
+ map.put("< 0.1 GHz", entry);
+ } else {
+ // Add a dot
+ map.put((flooredTenthGHz / 10) + "." + (flooredTenthGHz % 10) + " GHz", entry);
+ }
+
+ return map;
+
+ }
+ } catch (Exception ignored) {}
+ return null;
+ }));
+ // Gale end - metrics - processor frequency
+
+ // Gale start - metrics - physical memory
+ metrics.addCustomChart(new Metrics.DrilldownPie("physical_memory_total", () -> {
+ try {
+ long physicalMemory = new oshi.SystemInfo().getHardware().getMemory().getTotal();
+ if (physicalMemory > 0) {
+
+ Map<String, Map<String, Integer>> map = new HashMap<>(2);
+
+ // use floored MB as lower dimension
+ var flooredMB = physicalMemory / (1L << 20);
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put(flooredMB < 1 ? "< 1 MB" : flooredMB + " MB", 1);
+
+ // use floored GB as higher dimension
+ var flooredGB = physicalMemory / (1L << 30);
+ map.put(flooredGB < 1 ? "< 1 GB" : flooredGB + " GB", entry);
+
+ return map;
+
+ }
+ } catch (Exception ignored) {}
+ return null;
+ }));
+ // Gale end - metrics - physical memory
+
+ // Gale start - metrics - runtime max memory
+ metrics.addCustomChart(new Metrics.DrilldownPie("runtime_max_memory", () -> {
+
+ // get memory limit
+ long maxMemory = Runtime.getRuntime().maxMemory();
+ if (maxMemory <= 0) {
+ return null;
+ }
+
+ Map<String, Map<String, Integer>> map = new HashMap<>(2);
+
+ // in the case of no limit
+ if (maxMemory == Long.MAX_VALUE) {
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put("no limit", 1);
+ map.put("no limit", entry);
+ return map;
+ }
+
+ // use floored MB as lower dimension
+ var flooredMB = maxMemory / (1L << 20);
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put(flooredMB < 1 ? "< 1 MB" : flooredMB + " MB", 1);
+
+ // use floored GB as higher dimension
+ var flooredGB = maxMemory / (1L << 30);
+ map.put(flooredGB < 1 ? "< 1 GB" : flooredGB + " GB", entry);
+
+ return map;
+ }));
+ // Gale end - metrics - runtime max memory
+
}
}