Add loaded chunks count metrics
This commit is contained in:
parent
a48d73c30a
commit
c9fa96d792
6 changed files with 52 additions and 6 deletions
|
@ -7,10 +7,7 @@ import net.minecraft.server.MinecraftServer;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import ru.ruscalworld.fabricexporter.config.MainConfig;
|
import ru.ruscalworld.fabricexporter.config.MainConfig;
|
||||||
import ru.ruscalworld.fabricexporter.metrics.Entities;
|
import ru.ruscalworld.fabricexporter.metrics.*;
|
||||||
import ru.ruscalworld.fabricexporter.metrics.OnlinePlayers;
|
|
||||||
import ru.ruscalworld.fabricexporter.metrics.TicksPerSecond;
|
|
||||||
import ru.ruscalworld.fabricexporter.metrics.MillisPerTick;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
@ -35,6 +32,8 @@ public class FabricExporter implements ModInitializer {
|
||||||
metricUpdater.registerMetric(new TicksPerSecond());
|
metricUpdater.registerMetric(new TicksPerSecond());
|
||||||
metricUpdater.registerMetric(new MillisPerTick());
|
metricUpdater.registerMetric(new MillisPerTick());
|
||||||
metricUpdater.registerMetric(new Entities());
|
metricUpdater.registerMetric(new Entities());
|
||||||
|
metricUpdater.registerMetric(new LoadedChunks());
|
||||||
|
metricUpdater.registerMetric(new TotalLoadedChunks());
|
||||||
|
|
||||||
ServerLifecycleEvents.SERVER_STARTING.register(this::setServer);
|
ServerLifecycleEvents.SERVER_STARTING.register(this::setServer);
|
||||||
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import ru.ruscalworld.fabricexporter.FabricExporter;
|
import ru.ruscalworld.fabricexporter.FabricExporter;
|
||||||
|
import ru.ruscalworld.fabricexporter.util.TextUtil;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ public class Entities extends Metric {
|
||||||
for (String type : currentWorldEntities.keySet()) {
|
for (String type : currentWorldEntities.keySet()) {
|
||||||
Integer count = currentWorldEntities.get(type);
|
Integer count = currentWorldEntities.get(type);
|
||||||
EntityType<?> entityType = Registry.ENTITY_TYPE.get(new Identifier(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package ru.ruscalworld.fabricexporter.metrics;
|
||||||
|
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import ru.ruscalworld.fabricexporter.FabricExporter;
|
import ru.ruscalworld.fabricexporter.FabricExporter;
|
||||||
|
import ru.ruscalworld.fabricexporter.util.TextUtil;
|
||||||
|
|
||||||
public class OnlinePlayers extends Metric {
|
public class OnlinePlayers extends Metric {
|
||||||
public OnlinePlayers() {
|
public OnlinePlayers() {
|
||||||
|
@ -11,7 +12,7 @@ public class OnlinePlayers extends Metric {
|
||||||
@Override
|
@Override
|
||||||
public void update(FabricExporter exporter) {
|
public void update(FabricExporter exporter) {
|
||||||
for (ServerWorld world : exporter.getServer().getWorlds()) {
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue