This commit is contained in:
@@ -17,7 +17,9 @@ import java.net.InetSocketAddress;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public final class PrometheusSpigotPlugin extends JavaPlugin {
|
||||
private HttpServer httpServer;
|
||||
@@ -25,6 +27,7 @@ public final class PrometheusSpigotPlugin extends JavaPlugin {
|
||||
private MetricsRegistry metricsRegistry;
|
||||
private String bearerToken;
|
||||
private boolean countBlockMovementOnly;
|
||||
private BukkitTask snapshotTask;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -43,6 +46,8 @@ public final class PrometheusSpigotPlugin extends JavaPlugin {
|
||||
|
||||
metricsRegistry = new MetricsRegistry(getServer(), enableJvm, enableProcess);
|
||||
|
||||
scheduleSnapshotTask();
|
||||
|
||||
registerListeners();
|
||||
startHttpServer();
|
||||
}
|
||||
@@ -57,6 +62,10 @@ public final class PrometheusSpigotPlugin extends JavaPlugin {
|
||||
httpExecutor.shutdownNow();
|
||||
httpExecutor = null;
|
||||
}
|
||||
if (snapshotTask != null) {
|
||||
snapshotTask.cancel();
|
||||
snapshotTask = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
@@ -95,4 +104,12 @@ public final class PrometheusSpigotPlugin extends JavaPlugin {
|
||||
httpServer.start();
|
||||
getLogger().info(String.format(Locale.ROOT, "Prometheus endpoint listening on http://%s:%d%s", bindAddress, port, path));
|
||||
}
|
||||
|
||||
private void scheduleSnapshotTask() {
|
||||
int intervalSeconds = getConfig().getInt("metrics.entity_snapshot_interval_seconds", 15);
|
||||
long intervalTicks = Math.max(20L, intervalSeconds * 20L);
|
||||
|
||||
metricsRegistry.refreshEntitySnapshots();
|
||||
snapshotTask = Bukkit.getScheduler().runTaskTimer(this, metricsRegistry::refreshEntitySnapshots, intervalTicks, intervalTicks);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user