feat: add block place and craft metrics
Build / build (push) Successful in 4m54s

This commit is contained in:
dmg
2026-01-27 22:34:59 -05:00
parent 2648897197
commit dc539e83d1
4 changed files with 60 additions and 0 deletions
@@ -44,11 +44,13 @@ public final class MetricsRegistry {
private final LongAdder chunkGenerations = new LongAdder();
private final LongAdder pluginEnables = new LongAdder();
private final LongAdder pluginDisables = new LongAdder();
private final ConcurrentHashMap<String, LongAdder> blocksPlacedByMaterial = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, LongAdder> blocksBrokenByMaterial = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, LongAdder> deathsByCause = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, LongAdder> loginFailuresByReason = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, LongAdder> commandsBlocked = new ConcurrentHashMap<>();
private final ConcurrentHashMap<LabelPair, LongAdder> commandsExecuted = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, LongAdder> itemsCraftedByMaterial = new ConcurrentHashMap<>();
public MetricsRegistry(Server server, boolean enableJvm, boolean enableProcess) {
this.server = server;
@@ -85,6 +87,10 @@ public final class MetricsRegistry {
incrementLabeledCounter(blocksBrokenByMaterial, material.name());
}
public void incrementBlocksPlaced(Material material) {
incrementLabeledCounter(blocksPlacedByMaterial, material.name());
}
public void incrementPlayerDeath(EntityDamageEvent.DamageCause cause) {
incrementLabeledCounter(deathsByCause, cause.name());
}
@@ -123,6 +129,10 @@ public final class MetricsRegistry {
pluginDisables.increment();
}
public void incrementItemsCrafted(Material material) {
incrementLabeledCounter(itemsCraftedByMaterial, material.name());
}
public void refreshEntitySnapshots() {
Map<String, Long> entityCounts = new HashMap<>();
Map<String, Long> tileCounts = new HashMap<>();
@@ -168,10 +178,12 @@ public final class MetricsRegistry {
appendCounter(builder, "spigot_plugin_disable_total", "Total plugin disable events", pluginDisables.sum());
appendLabeledCounterAdder(builder, "spigot_blocks_broken_total", "Blocks broken by material", "material", blocksBrokenByMaterial);
appendLabeledCounterAdder(builder, "spigot_blocks_placed_total", "Blocks placed by material", "material", blocksPlacedByMaterial);
appendLabeledCounterAdder(builder, "spigot_player_deaths_total", "Player deaths by cause", "cause", deathsByCause);
appendLabeledCounterAdder(builder, "spigot_player_logins_failed_total", "Failed player logins by reason", "reason", loginFailuresByReason);
appendLabeledCounterAdder(builder, "spigot_commands_blocked_total", "Blocked commands by name", "command", commandsBlocked);
appendLabeledCounterAdder(builder, "spigot_commands_executed_total", "Commands executed by source", "command", "source", commandsExecuted);
appendLabeledCounterAdder(builder, "spigot_items_crafted_total", "Items crafted by material", "material", itemsCraftedByMaterial);
appendGauge(builder, "spigot_players_online", "Online player count", server.getOnlinePlayers().size());
appendGauge(builder, "spigot_players_max", "Max player slots", server.getMaxPlayers());