diff --git a/src/main/java/monkey/info/command/Prometheus.java b/src/main/java/monkey/info/command/Prometheus.java index 04303f7..3c2e56e 100644 --- a/src/main/java/monkey/info/command/Prometheus.java +++ b/src/main/java/monkey/info/command/Prometheus.java @@ -5,6 +5,7 @@ import io.prometheus.metrics.model.registry.PrometheusRegistry; import monkey.info.command.metrics.Metric; import monkey.info.command.metrics.Mobcaps; +import monkey.info.command.metrics.Player; import monkey.info.command.metrics.Tick; import org.jetbrains.annotations.Nullable; @@ -39,8 +40,9 @@ public void run() { public void start() { this.stop(); - this.registerMetric(new Tick()); this.registerMetric(new Mobcaps()); + this.registerMetric(new Player()); + this.registerMetric(new Tick()); if (metricUpdateLoop == null) metricUpdateLoop = new Timer("Metric Update Loop"); metricUpdateLoop.scheduleAtFixedRate(new TimerTask() { diff --git a/src/main/java/monkey/info/command/metrics/Mobcaps.java b/src/main/java/monkey/info/command/metrics/Mobcaps.java index efb4462..e0a265f 100644 --- a/src/main/java/monkey/info/command/metrics/Mobcaps.java +++ b/src/main/java/monkey/info/command/metrics/Mobcaps.java @@ -18,15 +18,16 @@ public Mobcaps() { public void update(MinecraftServer server) { // edit from: https://github.com/gnembon/fabric-carpet/blob/7486670918f733aaf6ae3b595290947802024d02/src/main/java/carpet/utils/SpawnReporter.java#L105 for (ServerWorld world : server.getWorlds()) { - RegistryKey dim = world.getRegistryKey(); SpawnHelper.Info lastSpawner = world.getChunkManager().getSpawnInfo(); - int chunkcount = SpawnReporter.chunkCounts.getOrDefault(dim, -1); if (lastSpawner != null) { + RegistryKey dim = world.getRegistryKey(); + String worldName = world.getRegistryKey().getValue().toString(); + int chunkcount = SpawnReporter.chunkCounts.getOrDefault(dim, -1); + for (SpawnGroup enumcreaturetype : SpawnGroup.values()) { Object2IntMap dimCounts = lastSpawner.getGroupToCount(); String enumcreature = enumcreaturetype.toString(); - String worldName = world.getRegistryKey().getValue().toString(); int cur = dimCounts.getOrDefault(enumcreaturetype, -1); int max = (int) (chunkcount * ((double) enumcreaturetype.getCapacity() / SpawnReporter.currentMagicNumber())); diff --git a/src/main/java/monkey/info/command/metrics/Player.java b/src/main/java/monkey/info/command/metrics/Player.java new file mode 100644 index 0000000..6e8c208 --- /dev/null +++ b/src/main/java/monkey/info/command/metrics/Player.java @@ -0,0 +1,32 @@ +package monkey.info.command.metrics; + +import carpet.patches.EntityPlayerMPFake; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.World; + +import java.util.List; + +public class Player extends Metric { + public Player() { + super("players_online", "Online players", "type", "world"); + } + + @Override + public void update(MinecraftServer server) { + // edit from: https://github.com/gnembon/fabric-carpet/blob/7486670918f733aaf6ae3b595290947802024d02/src/main/java/carpet/utils/SpawnReporter.java#L105 + for (ServerWorld world : server.getWorlds()) { + RegistryKey dim = world.getRegistryKey(); + List players = world.getPlayers(); + String worldName = world.getRegistryKey().getValue().toString(); + + long fakePlayers = players.stream().filter(player -> player instanceof EntityPlayerMPFake).count(); + long realPlayers = players.size() - fakePlayers; + + this.getGauge().labelValues("FAKE", worldName).set(fakePlayers); + this.getGauge().labelValues("REAL", worldName).set(realPlayers); + } + } +}