Skip to content

Commit

Permalink
Merge pull request #227 from sladkoff/feature/198-folia
Browse files Browse the repository at this point in the history
feat: Rudimentary Folia Support
  • Loading branch information
sladkoff authored Feb 29, 2024
2 parents f04c2f1 + 6516276 commit d502aab
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 36 deletions.
48 changes: 26 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,22 @@ You can use labels in your Prometheus scrape configuration to distinguish betwee
These are the stats that are currently exported by the plugin.
Label | Description
------------ | -------------
mc_players_total | Unique players on server (online + offline)
mc_whitelisted_players | Players count on the white list
mc_loaded_chunks_total | Chunks loaded per world
mc_players_online_total | Online players per world
mc_entities_total | Entities loaded per world (living + non-living)
mc_villagers_total | Villagers
mc_world_size | World size in bytes
mc_jvm_memory | JVM memory usage
mc_jvm_threads | JVM threads info
mc_tps | Server tickrate (TPS)
mc_tick_duration_median | Median Tick Duration (ns, usually last 100 ticks)
mc_tick_duration_average | Average Tick Duration (ns, usually last 100 ticks)
mc_tick_duration_min | Min Tick Duration (ns, usually last 100 ticks)
mc_tick_duration_max | Max Tick Duration (ns, usually last 100 ticks)
| Label | Description | Folia Support |
|--------------------------|----------------------------------------------------|---------------|
| mc_players_total | Unique players on server (online + offline) | ✅ |
| mc_whitelisted_players | Players count on the white list | ❌ |
| mc_loaded_chunks_total | Chunks loaded per world | ❌ |
| mc_players_online_total | Online players per world | ✅ |
| mc_entities_total | Entities loaded per world (living + non-living) | ❌ |
| mc_villagers_total | Villagers | ❌ |
| mc_world_size | World size in bytes | ✅ |
| mc_jvm_memory | JVM memory usage | ✅ |
| mc_jvm_threads | JVM threads info | ✅ |
| mc_tps | Server tickrate (TPS) | ❌ |
| mc_tick_duration_median | Median Tick Duration (ns, usually last 100 ticks) | ❌ |
| mc_tick_duration_average | Average Tick Duration (ns, usually last 100 ticks) | ❌ |
| mc_tick_duration_min | Min Tick Duration (ns, usually last 100 ticks) | ❌ |
| mc_tick_duration_max | Max Tick Duration (ns, usually last 100 ticks) | ❌ |
## Player metrics (experimental!)
Expand All @@ -131,10 +131,10 @@ enable_metrics:
This will enable the additional metrics.
Label | Description
------------ | -------------
mc_player_statistic | Player statistics
mc_player_online | Online state by player name
| Label | Description | Folia |
|---------------------|-----------------------------|-------|
| mc_player_statistic | Player statistics | ❌ |
| mc_player_online | Online state by player name | ❌ |
There's a sample [dashboard](https://raw.githubusercontent.com/sladkoff/minecraft-prometheus-exporter/master/dashboards/minecraft-players-dashboard.json)
available to get you started.
Expand Down Expand Up @@ -188,15 +188,19 @@ public class MyPluginCommand extends PluginCommand {

#### Minecraft Server

#### Officially supported
##### Officially supported

> 1.11.x – 1.20.x
#### Tested
##### Tested
- 1.20.1
- 1.20.4

#### Java

- Java 11 or higher is required (Java 8 is not supported due to [this issue](https://github.com/sladkoff/minecraft-prometheus-exporter/issues/161))
- There is a known [issue](https://github.com/sladkoff/minecraft-prometheus-exporter/issues/197) with Azul JVM

#### Folia

There is currently rudimentary support for Folia servers. Only selected metrics are supported.
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ services:
image: itzg/minecraft-server:2024.2.0
environment:
EULA: "true"
TYPE: "PAPER"
VERSION: "1.20.4"
PLUGINS: |
https://github.com/sladkoff/minecraft-prometheus-exporter/releases/download/v2.6.0/minecraft-prometheus-exporter-2.6.0.jar
TYPE: "FOLIA"
# TYPE: "PAPER"
# PLUGINS: |
# https://github.com/sladkoff/minecraft-prometheus-exporter/releases/download/v2.5.0/minecraft-prometheus-exporter-2.5.0.jar

ports:
- "25565:25565"
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/de/sldk/mc/config/PrometheusExporterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import de.sldk.mc.MetricRegistry;
import de.sldk.mc.PrometheusExporter;
import de.sldk.mc.metrics.*;
import de.sldk.mc.metrics.TickDurationAverageCollector;
import de.sldk.mc.metrics.TickDurationMaxCollector;
import de.sldk.mc.metrics.TickDurationMedianCollector;
import de.sldk.mc.metrics.TickDurationMinCollector;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;

Expand Down Expand Up @@ -65,12 +61,18 @@ public void loadDefaultsAndSave() {
public void enableConfiguredMetrics() {
PrometheusExporterConfig.METRICS
.forEach(metricConfig -> {
String metricName = metricConfig.getClass().getSimpleName();
Metric metric = metricConfig.getMetric(prometheusExporter);
String metricName = metric.getClass().getSimpleName();
try {
Metric metric = metricConfig.getMetric(prometheusExporter);
Boolean enabled = get(metricConfig);

var foliaSupported = metric.isFoliaCapable();

if (Boolean.TRUE.equals(enabled)) {
if (isFolia() && !foliaSupported) {
prometheusExporter.getLogger().warning("Metric " + metricName + " is not supported in Folia and will not be enabled");
return;
}
metric.enable();
}

Expand All @@ -87,4 +89,17 @@ public void enableConfiguredMetrics() {
public <T> T get(PluginConfig<T> config) {
return config.get(prometheusExporter.getConfig());
}

/**
* @return true if the server is running Folia
* @see <a href="https://docs.papermc.io/paper/dev/folia-support">Folia Support</a>
*/
private static boolean isFolia() {
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/de/sldk/mc/metrics/Entities.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* Get current count of all entities.
*
* <p>
* Entities are labelled by
* <ol>
* <li> world,
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/de/sldk/mc/metrics/GarbageCollectorWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public GarbageCollectorWrapper(Plugin plugin) {
@Override
protected void doCollect() {}

@Override
public boolean isFoliaCapable() {
return true;
}

@Override
public boolean isAsyncCapable() {
return true;
}

private static class GarbageCollectorExportsCollector extends Collector {
private static final GarbageCollectorExports garbageCollectorExports = new GarbageCollectorExports();

Expand All @@ -23,4 +33,4 @@ public List<MetricFamilySamples> collect() {
return HotspotPrefixer.prefixFromCollector(garbageCollectorExports);
}
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/de/sldk/mc/metrics/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@ public void doCollect() {
MEMORY.labels("free").set(Runtime.getRuntime().freeMemory());
MEMORY.labels("allocated").set(Runtime.getRuntime().totalMemory());
}

@Override
public boolean isFoliaCapable() {
return true;
}

@Override
public boolean isAsyncCapable() {
return true;
}
}
8 changes: 7 additions & 1 deletion src/main/java/de/sldk/mc/metrics/Metric.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public CompletableFuture<Void> collect() {
}
return null;
}).get();
} catch (InterruptedException | ExecutionException e) {
} catch (Exception e) {
logException(e);
}
});
Expand All @@ -77,11 +77,17 @@ protected boolean isAsyncCapable() {
return false;
}

public boolean isFoliaCapable() {
return false;
}

private void logException(Exception e) {
final Logger log = plugin.getLogger();
final String className = getClass().getSimpleName();

log.throwing(className, "collect", e);
log.info("Failed to collect " + className + ": ");
e.printStackTrace();
}

protected static String prefix(String name) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/de/sldk/mc/metrics/PlayersOnlineTotal.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ protected void clear() {
protected void collect(World world) {
PLAYERS_ONLINE.labels(world.getName()).set(world.getPlayers().size());
}

@Override
public boolean isFoliaCapable() {
return true;
}

@Override
public boolean isAsyncCapable() {
return true;
}
}
5 changes: 5 additions & 0 deletions src/main/java/de/sldk/mc/metrics/PlayersTotal.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public void doCollect() {
public boolean isAsyncCapable() {
return true;
}

@Override
public boolean isFoliaCapable() {
return true;
}
}
12 changes: 11 additions & 1 deletion src/main/java/de/sldk/mc/metrics/ThreadsWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@ public List<MetricFamilySamples> collect() {
return HotspotPrefixer.prefixFromCollector(threadExports);
}
}
}

@Override
public boolean isFoliaCapable() {
return true;
}

@Override
public boolean isAsyncCapable() {
return true;
}
}
1 change: 1 addition & 0 deletions src/main/java/de/sldk/mc/metrics/WhitelistedPlayers.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public WhitelistedPlayers(Plugin plugin) {
public void doCollect() {
PLAYERS.set(Bukkit.getWhitelistedPlayers().size());
}

}
8 changes: 7 additions & 1 deletion src/main/java/de/sldk/mc/metrics/WorldSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import de.sldk.mc.utils.PathFileSize;
import io.prometheus.client.Gauge;
import java.util.logging.Logger;
import org.bukkit.World;
import org.bukkit.plugin.Plugin;

import java.util.logging.Logger;

public class WorldSize extends WorldMetric {

private final Logger log;
Expand Down Expand Up @@ -41,4 +42,9 @@ public void collect(World world) {
protected boolean isAsyncCapable() {
return true;
}

@Override
public boolean isFoliaCapable() {
return true;
}
}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ author: sldk
main: de.sldk.mc.PrometheusExporter
website: sldk.de
api-version: 1.16
folia-supported: true

0 comments on commit d502aab

Please sign in to comment.