Skip to content

Commit b1fa9b2

Browse files
committed
WIP: debug locally
1 parent fc7439c commit b1fa9b2

File tree

6 files changed

+11
-47
lines changed

6 files changed

+11
-47
lines changed

docker-compose.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ services:
55
image: itzg/minecraft-server:2024.2.0
66
environment:
77
EULA: "true"
8-
TYPE: "PAPER"
8+
TYPE: "FOLIA"
99
VERSION: "1.20.4"
10-
PLUGINS: |
11-
https://github.com/sladkoff/minecraft-prometheus-exporter/releases/download/v2.6.0/minecraft-prometheus-exporter-2.6.0.jar
10+
# PLUGINS: |
11+
# https://github.com/sladkoff/minecraft-prometheus-exporter/releases/download/v2.5.0/minecraft-prometheus-exporter-2.5.0.jar
1212

1313
ports:
1414
- "25565:25565"
1515
- "9940:9940"
16+
expose:
17+
- 9940
1618
volumes:
1719
- ./docker/data:/data
1820
stdin_open: true

src/main/java/de/sldk/mc/MetricsController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void handle(String target, Request request, HttpServletRequest httpServle
4141
request.setHandled(true);
4242
} catch (InterruptedException | ExecutionException e) {
4343
exporter.getLogger().log(Level.WARNING, "Failed to read server statistic: " + e.getMessage());
44-
exporter.getLogger().log(Level.FINE, "Failed to read server statistic: ", e);
44+
exporter.getLogger().log(Level.INFO, "Failed to read server statistic: ", e);
4545
response.sendError(HttpStatus.INTERNAL_SERVER_ERROR_500);
4646
}
4747
}

src/main/java/de/sldk/mc/PrometheusExporter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private void startMetricsServer() {
2424
String host = config.get(PrometheusExporterConfig.HOST);
2525
Integer port = config.get(PrometheusExporterConfig.PORT);
2626

27-
server = new MetricsServer(host, port, this);
27+
server = new MetricsServer(host, port, this);
2828

2929
try {
3030
server.start();
@@ -41,7 +41,7 @@ public void onDisable() {
4141
server.stop();
4242
} catch (Exception e) {
4343
getLogger().log(Level.WARNING, "Failed to stop metrics server gracefully: " + e.getMessage());
44-
getLogger().log(Level.FINE, "Failed to stop metrics server gracefully", e);
44+
getLogger().log(Level.INFO, "Failed to stop metrics server gracefully", e);
4545
}
4646
}
4747

src/main/java/de/sldk/mc/metrics/Metric.java

+2-36
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import io.prometheus.client.Collector;
44
import io.prometheus.client.CollectorRegistry;
5-
import org.bukkit.Bukkit;
65
import org.bukkit.plugin.Plugin;
76

87
import java.util.concurrent.CompletableFuture;
9-
import java.util.concurrent.ExecutionException;
108
import java.util.logging.Logger;
119

1210
public abstract class Metric {
@@ -34,49 +32,17 @@ public CompletableFuture<Void> collect() {
3432
}
3533

3634
/* If metric is capable of async execution run it on a thread pool */
37-
if (isAsyncCapable()) {
38-
39-
try {
40-
doCollect();
41-
}
42-
catch (Exception e) {
43-
logException(e);
44-
}
45-
return;
46-
}
4735

48-
/*
49-
* Otherwise run the metric on the main thread and make the
50-
* thread on thread pool wait for completion
51-
*/
5236
try {
53-
Bukkit.getScheduler().callSyncMethod(plugin, () -> {
54-
try {
55-
doCollect();
56-
}
57-
catch (Exception e) {
58-
logException(e);
59-
}
60-
return null;
61-
}).get();
62-
} catch (InterruptedException | ExecutionException e) {
37+
doCollect();
38+
} catch (Exception e) {
6339
logException(e);
6440
}
6541
});
6642
}
6743

6844
protected abstract void doCollect();
6945

70-
/**
71-
* This method is called during the Metric collection
72-
* to determine if it is safe to do it async.
73-
* By default, all Metrics are sync unless this method
74-
* is overridden.
75-
*/
76-
protected boolean isAsyncCapable() {
77-
return false;
78-
}
79-
8046
private void logException(Exception e) {
8147
final Logger log = plugin.getLogger();
8248
final String className = getClass().getSimpleName();

src/main/java/de/sldk/mc/metrics/WorldSize.java

-5
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,4 @@ public void collect(World world) {
3636
log.throwing(this.getClass().getSimpleName(), "collect", t);
3737
}
3838
}
39-
40-
@Override
41-
protected boolean isAsyncCapable() {
42-
return true;
43-
}
4439
}

src/main/resources/plugin.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ author: sldk
44
main: de.sldk.mc.PrometheusExporter
55
website: sldk.de
66
api-version: 1.16
7+
folia-supported: true

0 commit comments

Comments
 (0)