Add loaded chunks count metrics

This commit is contained in:
RuscalWorld 2021-05-25 00:43:14 +03:00
parent a48d73c30a
commit c9fa96d792
No known key found for this signature in database
GPG key ID: 4F53776031D128ED
6 changed files with 52 additions and 6 deletions

View file

@ -7,10 +7,7 @@ import net.minecraft.server.MinecraftServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import ru.ruscalworld.fabricexporter.config.MainConfig;
import ru.ruscalworld.fabricexporter.metrics.Entities;
import ru.ruscalworld.fabricexporter.metrics.OnlinePlayers;
import ru.ruscalworld.fabricexporter.metrics.TicksPerSecond;
import ru.ruscalworld.fabricexporter.metrics.MillisPerTick;
import ru.ruscalworld.fabricexporter.metrics.*;
import java.io.IOException;
import java.util.Timer;
@ -35,6 +32,8 @@ public class FabricExporter implements ModInitializer {
metricUpdater.registerMetric(new TicksPerSecond());
metricUpdater.registerMetric(new MillisPerTick());
metricUpdater.registerMetric(new Entities());
metricUpdater.registerMetric(new LoadedChunks());
metricUpdater.registerMetric(new TotalLoadedChunks());
ServerLifecycleEvents.SERVER_STARTING.register(this::setServer);
ServerLifecycleEvents.SERVER_STARTED.register(server -> {

View file

@ -6,6 +6,7 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import ru.ruscalworld.fabricexporter.FabricExporter;
import ru.ruscalworld.fabricexporter.util.TextUtil;
import java.util.HashMap;
@ -28,7 +29,7 @@ public class Entities extends Metric {
for (String type : currentWorldEntities.keySet()) {
Integer count = currentWorldEntities.get(type);
EntityType<?> entityType = Registry.ENTITY_TYPE.get(new Identifier(type));
this.getGauge().labels(world.getRegistryKey().getValue().getPath(), entityType.getSpawnGroup().getName(), type).set(count);
this.getGauge().labels(TextUtil.getWorldName(world), entityType.getSpawnGroup().getName(), type).set(count);
}
}
}

View file

@ -0,0 +1,18 @@
package ru.ruscalworld.fabricexporter.metrics;
import net.minecraft.server.world.ServerWorld;
import ru.ruscalworld.fabricexporter.FabricExporter;
import ru.ruscalworld.fabricexporter.util.TextUtil;
public class LoadedChunks extends Metric {
public LoadedChunks() {
super("loaded_chunks", "Amount of currently loaded chunks on server", "world");
}
@Override
public void update(FabricExporter exporter) {
for (ServerWorld world : exporter.getServer().getWorlds()) {
this.getGauge().labels(TextUtil.getWorldName(world)).set(world.getChunkManager().getLoadedChunkCount());
}
}
}

View file

@ -2,6 +2,7 @@ package ru.ruscalworld.fabricexporter.metrics;
import net.minecraft.server.world.ServerWorld;
import ru.ruscalworld.fabricexporter.FabricExporter;
import ru.ruscalworld.fabricexporter.util.TextUtil;
public class OnlinePlayers extends Metric {
public OnlinePlayers() {
@ -11,7 +12,7 @@ public class OnlinePlayers extends Metric {
@Override
public void update(FabricExporter exporter) {
for (ServerWorld world : exporter.getServer().getWorlds()) {
this.getGauge().labels(world.getRegistryKey().getValue().getPath()).set(world.getPlayers().size());
this.getGauge().labels(TextUtil.getWorldName(world)).set(world.getPlayers().size());
}
}
}

View file

@ -0,0 +1,18 @@
package ru.ruscalworld.fabricexporter.metrics;
import net.minecraft.server.world.ServerWorld;
import ru.ruscalworld.fabricexporter.FabricExporter;
import ru.ruscalworld.fabricexporter.util.TextUtil;
public class TotalLoadedChunks extends Metric {
public TotalLoadedChunks() {
super("total_loaded_chunks", "Amount of total loaded chunks on server", "world");
}
@Override
public void update(FabricExporter exporter) {
for (ServerWorld world : exporter.getServer().getWorlds()) {
this.getGauge().labels(TextUtil.getWorldName(world)).set(world.getChunkManager().getTotalChunksLoadedCount());
}
}
}

View file

@ -0,0 +1,9 @@
package ru.ruscalworld.fabricexporter.util;
import net.minecraft.server.world.ServerWorld;
public class TextUtil {
public static String getWorldName(ServerWorld world) {
return world.getRegistryKey().getValue().getPath();
}
}