Skip to content

Commit d502aab

Browse files
authored
Merge pull request #227 from sladkoff/feature/198-folia
feat: Rudimentary Folia Support
2 parents f04c2f1 + 6516276 commit d502aab

13 files changed

+115
-36
lines changed

README.md

+26-22
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,22 @@ You can use labels in your Prometheus scrape configuration to distinguish betwee
9393
9494
These are the stats that are currently exported by the plugin.
9595
96-
Label | Description
97-
------------ | -------------
98-
mc_players_total | Unique players on server (online + offline)
99-
mc_whitelisted_players | Players count on the white list
100-
mc_loaded_chunks_total | Chunks loaded per world
101-
mc_players_online_total | Online players per world
102-
mc_entities_total | Entities loaded per world (living + non-living)
103-
mc_villagers_total | Villagers
104-
mc_world_size | World size in bytes
105-
mc_jvm_memory | JVM memory usage
106-
mc_jvm_threads | JVM threads info
107-
mc_tps | Server tickrate (TPS)
108-
mc_tick_duration_median | Median Tick Duration (ns, usually last 100 ticks)
109-
mc_tick_duration_average | Average Tick Duration (ns, usually last 100 ticks)
110-
mc_tick_duration_min | Min Tick Duration (ns, usually last 100 ticks)
111-
mc_tick_duration_max | Max Tick Duration (ns, usually last 100 ticks)
96+
| Label | Description | Folia Support |
97+
|--------------------------|----------------------------------------------------|---------------|
98+
| mc_players_total | Unique players on server (online + offline) | ✅ |
99+
| mc_whitelisted_players | Players count on the white list | ❌ |
100+
| mc_loaded_chunks_total | Chunks loaded per world | ❌ |
101+
| mc_players_online_total | Online players per world | ✅ |
102+
| mc_entities_total | Entities loaded per world (living + non-living) | ❌ |
103+
| mc_villagers_total | Villagers | ❌ |
104+
| mc_world_size | World size in bytes | ✅ |
105+
| mc_jvm_memory | JVM memory usage | ✅ |
106+
| mc_jvm_threads | JVM threads info | ✅ |
107+
| mc_tps | Server tickrate (TPS) | ❌ |
108+
| mc_tick_duration_median | Median Tick Duration (ns, usually last 100 ticks) | ❌ |
109+
| mc_tick_duration_average | Average Tick Duration (ns, usually last 100 ticks) | ❌ |
110+
| mc_tick_duration_min | Min Tick Duration (ns, usually last 100 ticks) | ❌ |
111+
| mc_tick_duration_max | Max Tick Duration (ns, usually last 100 ticks) | ❌ |
112112
113113
## Player metrics (experimental!)
114114
@@ -131,10 +131,10 @@ enable_metrics:
131131
132132
This will enable the additional metrics.
133133
134-
Label | Description
135-
------------ | -------------
136-
mc_player_statistic | Player statistics
137-
mc_player_online | Online state by player name
134+
| Label | Description | Folia |
135+
|---------------------|-----------------------------|-------|
136+
| mc_player_statistic | Player statistics | ❌ |
137+
| mc_player_online | Online state by player name | ❌ |
138138
139139
There's a sample [dashboard](https://raw.githubusercontent.com/sladkoff/minecraft-prometheus-exporter/master/dashboards/minecraft-players-dashboard.json)
140140
available to get you started.
@@ -188,15 +188,19 @@ public class MyPluginCommand extends PluginCommand {
188188

189189
#### Minecraft Server
190190

191-
#### Officially supported
191+
##### Officially supported
192192

193193
> 1.11.x – 1.20.x
194194
195-
#### Tested
195+
##### Tested
196196
- 1.20.1
197197
- 1.20.4
198198

199199
#### Java
200200

201201
- Java 11 or higher is required (Java 8 is not supported due to [this issue](https://github.com/sladkoff/minecraft-prometheus-exporter/issues/161))
202202
- There is a known [issue](https://github.com/sladkoff/minecraft-prometheus-exporter/issues/197) with Azul JVM
203+
204+
#### Folia
205+
206+
There is currently rudimentary support for Folia servers. Only selected metrics are supported.

docker-compose.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ services:
55
image: itzg/minecraft-server:2024.2.0
66
environment:
77
EULA: "true"
8-
TYPE: "PAPER"
98
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
9+
TYPE: "FOLIA"
10+
# TYPE: "PAPER"
11+
# PLUGINS: |
12+
# https://github.com/sladkoff/minecraft-prometheus-exporter/releases/download/v2.5.0/minecraft-prometheus-exporter-2.5.0.jar
1213

1314
ports:
1415
- "25565:25565"

src/main/java/de/sldk/mc/config/PrometheusExporterConfig.java

+21-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
import de.sldk.mc.MetricRegistry;
44
import de.sldk.mc.PrometheusExporter;
55
import de.sldk.mc.metrics.*;
6-
import de.sldk.mc.metrics.TickDurationAverageCollector;
7-
import de.sldk.mc.metrics.TickDurationMaxCollector;
8-
import de.sldk.mc.metrics.TickDurationMedianCollector;
9-
import de.sldk.mc.metrics.TickDurationMinCollector;
106
import org.bukkit.configuration.file.FileConfiguration;
117
import org.bukkit.plugin.Plugin;
128

@@ -65,12 +61,18 @@ public void loadDefaultsAndSave() {
6561
public void enableConfiguredMetrics() {
6662
PrometheusExporterConfig.METRICS
6763
.forEach(metricConfig -> {
68-
String metricName = metricConfig.getClass().getSimpleName();
64+
Metric metric = metricConfig.getMetric(prometheusExporter);
65+
String metricName = metric.getClass().getSimpleName();
6966
try {
70-
Metric metric = metricConfig.getMetric(prometheusExporter);
7167
Boolean enabled = get(metricConfig);
7268

69+
var foliaSupported = metric.isFoliaCapable();
70+
7371
if (Boolean.TRUE.equals(enabled)) {
72+
if (isFolia() && !foliaSupported) {
73+
prometheusExporter.getLogger().warning("Metric " + metricName + " is not supported in Folia and will not be enabled");
74+
return;
75+
}
7476
metric.enable();
7577
}
7678

@@ -87,4 +89,17 @@ public void enableConfiguredMetrics() {
8789
public <T> T get(PluginConfig<T> config) {
8890
return config.get(prometheusExporter.getConfig());
8991
}
92+
93+
/**
94+
* @return true if the server is running Folia
95+
* @see <a href="https://docs.papermc.io/paper/dev/folia-support">Folia Support</a>
96+
*/
97+
private static boolean isFolia() {
98+
try {
99+
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
100+
return true;
101+
} catch (ClassNotFoundException e) {
102+
return false;
103+
}
104+
}
90105
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
/**
1515
* Get current count of all entities.
16-
*
16+
* <p>
1717
* Entities are labelled by
1818
* <ol>
1919
* <li> world,

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ public GarbageCollectorWrapper(Plugin plugin) {
1515
@Override
1616
protected void doCollect() {}
1717

18+
@Override
19+
public boolean isFoliaCapable() {
20+
return true;
21+
}
22+
23+
@Override
24+
public boolean isAsyncCapable() {
25+
return true;
26+
}
27+
1828
private static class GarbageCollectorExportsCollector extends Collector {
1929
private static final GarbageCollectorExports garbageCollectorExports = new GarbageCollectorExports();
2030

@@ -23,4 +33,4 @@ public List<MetricFamilySamples> collect() {
2333
return HotspotPrefixer.prefixFromCollector(garbageCollectorExports);
2434
}
2535
}
26-
}
36+
}

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

+10
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ public void doCollect() {
2121
MEMORY.labels("free").set(Runtime.getRuntime().freeMemory());
2222
MEMORY.labels("allocated").set(Runtime.getRuntime().totalMemory());
2323
}
24+
25+
@Override
26+
public boolean isFoliaCapable() {
27+
return true;
28+
}
29+
30+
@Override
31+
public boolean isAsyncCapable() {
32+
return true;
33+
}
2434
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public CompletableFuture<Void> collect() {
5959
}
6060
return null;
6161
}).get();
62-
} catch (InterruptedException | ExecutionException e) {
62+
} catch (Exception e) {
6363
logException(e);
6464
}
6565
});
@@ -77,11 +77,17 @@ protected boolean isAsyncCapable() {
7777
return false;
7878
}
7979

80+
public boolean isFoliaCapable() {
81+
return false;
82+
}
83+
8084
private void logException(Exception e) {
8185
final Logger log = plugin.getLogger();
8286
final String className = getClass().getSimpleName();
8387

8488
log.throwing(className, "collect", e);
89+
log.info("Failed to collect " + className + ": ");
90+
e.printStackTrace();
8591
}
8692

8793
protected static String prefix(String name) {

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

+10
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,14 @@ protected void clear() {
2424
protected void collect(World world) {
2525
PLAYERS_ONLINE.labels(world.getName()).set(world.getPlayers().size());
2626
}
27+
28+
@Override
29+
public boolean isFoliaCapable() {
30+
return true;
31+
}
32+
33+
@Override
34+
public boolean isAsyncCapable() {
35+
return true;
36+
}
2737
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ public void doCollect() {
2424
public boolean isAsyncCapable() {
2525
return true;
2626
}
27+
28+
@Override
29+
public boolean isFoliaCapable() {
30+
return true;
31+
}
2732
}

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ public List<MetricFamilySamples> collect() {
2323
return HotspotPrefixer.prefixFromCollector(threadExports);
2424
}
2525
}
26-
}
26+
27+
@Override
28+
public boolean isFoliaCapable() {
29+
return true;
30+
}
31+
32+
@Override
33+
public boolean isAsyncCapable() {
34+
return true;
35+
}
36+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ public WhitelistedPlayers(Plugin plugin) {
1919
public void doCollect() {
2020
PLAYERS.set(Bukkit.getWhitelistedPlayers().size());
2121
}
22+
2223
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import de.sldk.mc.utils.PathFileSize;
44
import io.prometheus.client.Gauge;
5-
import java.util.logging.Logger;
65
import org.bukkit.World;
76
import org.bukkit.plugin.Plugin;
87

8+
import java.util.logging.Logger;
9+
910
public class WorldSize extends WorldMetric {
1011

1112
private final Logger log;
@@ -41,4 +42,9 @@ public void collect(World world) {
4142
protected boolean isAsyncCapable() {
4243
return true;
4344
}
45+
46+
@Override
47+
public boolean isFoliaCapable() {
48+
return true;
49+
}
4450
}

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)