Start updater only after minecraft server starts

Fixes NPE during server startup
This commit is contained in:
RuscalWorld 2021-05-24 19:56:54 +03:00
parent a24c0547de
commit 66a1cd5741
No known key found for this signature in database
GPG key ID: 4F53776031D128ED

View file

@ -27,29 +27,28 @@ public class FabricExporter implements ModInitializer {
e.printStackTrace();
}
ServerLifecycleEvents.SERVER_STARTED.register(this::setServer);
try {
new HTTPServer(this.getConfig().getPort());
} catch (IOException e) {
e.printStackTrace();
}
MetricUpdater metricUpdater = new MetricUpdater(this);
metricUpdater.registerMetric(new OnlinePlayers());
ServerLifecycleEvents.SERVER_STARTING.register(this::setServer);
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
try {
int port = this.getConfig().getPort();
new HTTPServer(port);
FabricExporter.getLogger().info("Prometheus exporter server is now listening on port " + port);
Timer timer = new Timer();
timer.schedule(metricUpdater, 1000, this.getConfig().getUpdateInterval());
} catch (IOException e) {
e.printStackTrace();
}
});
}
public static Logger getLogger() {
return LogManager.getLogger();
}
public static String getMetricName(String name) {
return "mc_" + name;
}
public MinecraftServer getServer() {
return server;
}