Add TPS and MSPT metrics
This commit is contained in:
parent
66a1cd5741
commit
2687db425a
7 changed files with 59 additions and 2 deletions
|
@ -8,6 +8,8 @@ import org.apache.logging.log4j.LogManager;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import ru.ruscalworld.fabricexporter.config.MainConfig;
|
||||
import ru.ruscalworld.fabricexporter.metrics.OnlinePlayers;
|
||||
import ru.ruscalworld.fabricexporter.metrics.TicksPerSecond;
|
||||
import ru.ruscalworld.fabricexporter.metrics.MillisPerTick;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Timer;
|
||||
|
@ -29,6 +31,8 @@ public class FabricExporter implements ModInitializer {
|
|||
|
||||
MetricUpdater metricUpdater = new MetricUpdater(this);
|
||||
metricUpdater.registerMetric(new OnlinePlayers());
|
||||
metricUpdater.registerMetric(new TicksPerSecond());
|
||||
metricUpdater.registerMetric(new MillisPerTick());
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTING.register(this::setServer);
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ru.ruscalworld.fabricexporter;
|
||||
|
||||
import ru.ruscalworld.fabricexporter.metrics.Metric;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TimerTask;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ru.ruscalworld.fabricexporter;
|
||||
package ru.ruscalworld.fabricexporter.metrics;
|
||||
|
||||
import io.prometheus.client.Gauge;
|
||||
import ru.ruscalworld.fabricexporter.FabricExporter;
|
||||
|
||||
public abstract class Metric {
|
||||
private final Gauge gauge;
|
|
@ -0,0 +1,19 @@
|
|||
package ru.ruscalworld.fabricexporter.metrics;
|
||||
|
||||
import me.lucko.spark.api.statistic.StatisticWindow;
|
||||
import me.lucko.spark.api.statistic.misc.DoubleAverageInfo;
|
||||
import me.lucko.spark.api.statistic.types.GenericStatistic;
|
||||
import ru.ruscalworld.fabricexporter.FabricExporter;
|
||||
|
||||
public class MillisPerTick extends SparkMetric {
|
||||
public MillisPerTick() {
|
||||
super("mspt", "Milliseconds per tick (MSPT)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCurrentValue(FabricExporter exporter) {
|
||||
GenericStatistic<DoubleAverageInfo, StatisticWindow.MillisPerTick> mspt = this.getSpark().mspt();
|
||||
if (mspt == null) return 0;
|
||||
return mspt.poll(StatisticWindow.MillisPerTick.MINUTES_1).mean();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package ru.ruscalworld.fabricexporter.metrics;
|
||||
|
||||
import ru.ruscalworld.fabricexporter.FabricExporter;
|
||||
import ru.ruscalworld.fabricexporter.Metric;
|
||||
|
||||
public class OnlinePlayers extends Metric {
|
||||
public OnlinePlayers() {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package ru.ruscalworld.fabricexporter.metrics;
|
||||
|
||||
import me.lucko.spark.api.Spark;
|
||||
import me.lucko.spark.api.SparkProvider;
|
||||
|
||||
public abstract class SparkMetric extends Metric {
|
||||
public SparkMetric(String name, String help) {
|
||||
super(name, help);
|
||||
}
|
||||
|
||||
public Spark getSpark() {
|
||||
return SparkProvider.get();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package ru.ruscalworld.fabricexporter.metrics;
|
||||
|
||||
import me.lucko.spark.api.statistic.StatisticWindow;
|
||||
import me.lucko.spark.api.statistic.types.DoubleStatistic;
|
||||
import ru.ruscalworld.fabricexporter.FabricExporter;
|
||||
|
||||
public class TicksPerSecond extends SparkMetric {
|
||||
public TicksPerSecond() {
|
||||
super("tps", "Current TPS on server");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCurrentValue(FabricExporter exporter) {
|
||||
DoubleStatistic<StatisticWindow.TicksPerSecond> tps = this.getSpark().tps();
|
||||
if (tps == null) return 20;
|
||||
return tps.poll(StatisticWindow.TicksPerSecond.MINUTES_1);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue