A Bukkit plugin which exports minecraft server stats to Prometheus
A Bukkit plugin which exports Minecraft server stats for Prometheus.
Drop the prometheus-exporter.jar into your Bukkit plugins directory and start your Minecraft server.
After startup, the Prometheus metrics endpoint should be available at
localhost:9225/metrics(assuming localhost is the server hostname).
The metrics port can be customized in the plugin's config.yml (a default config will be created after the first use).
Here's a default config with annotations.
# Note that the HTTP server binds to localhost by default. # If your Prometheus runs on another host or inside a Kubernetes cluster # set this to any reachable IP or 0.0.0.0 to listen on all interfaces. host: localhost # The port can be changed in case it conflicts with any other application. port: 9225 # Metrics can be enabled individually. Metrics which are disabled # by default may have a performance impact on your server. # See the rest of the README for more information. enable_metrics: jvm_threads: true jvm_gc: true players_total: true entities_total: true living_entities_total: true loaded_chunks_total: true jvm_memory: true players_online_total: true tps: true tick_duration_average: true tick_duration_median: true tick_duration_min: false tick_duration_max: true player_online: false player_statistic: false
Add the following job to the
scrape_configssection of your Prometheus configuration:
- job_name: 'minecraft' static_configs: - targets: ['localhost:9225'] labels: server_name: 'my-awesome-server'
You can use labels in your Prometheus scrape configuration to distinguish between multiple servers:
- job_name: 'minecraft' static_configs: - targets: ['localhost:9225'] labels: server_name: 'server1' - targets: ['localhost:9226'] labels: server_name: 'server2'
These are the stats that are currently exported by the plugin.
Label |
Description |
---|---|
mcplayerstotal | Unique players on server (online + offline) |
mcloadedchunkstotal | Chunks loaded per world |
mcplayersonlinetotal | Online players per world |
mcentitiestotal | Entities loaded per world (living + non-living) |
mcvillagerstotal | Villagers |
mcjvmmemory | JVM memory usage |
mcjvmthreads | JVM threads info |
mctps | Server tickrate (TPS) |
mctickdurationmedian | Median Tick Duration (ns, usually last 100 ticks) |
mctickdurationaverage | Average Tick Duration (ns, usually last 100 ticks) |
mctickdurationmin | Min Tick Duration (ns, usually last 100 ticks) |
mctickduration_max | Max Tick Duration (ns, usually last 100 ticks) |
:warning: The following feature is against Prometheus best-practices and is not recommended for production servers!
There is an option to export per-player statistics like the number of blocks mined, mobs killed, items used, etc. The amount of data stored in Prometheus can dramatically increase when this is enabled as individual time-series will be generated for each player that has ever been seen on the server. The statistic collection may also have an impact on the Minecraft server performance for bigger servers but it has not been measured or tested.
On the other hand this should be quite safe for small private servers with limited players.
You can enable the experimental player export in the config.yaml.
enable_metrics: player_online: true player_statistic: true
This will enable the additional metrics.
Label |
Description |
---|---|
mcplayerstatistic | Player statistics |
mcplayeronline | Online state by player name |
There's a sample dashboard available to get you started.
You can easily collect metrics about your own plugin.
io.prometheus simpleclient_common ...
This pseudo code shows how you would count invocations of a plugin command.
public class MyPluginCommand extends PluginCommand {// Register your counter private Counter commandCounter = Counter.build() .name("mc_my_plugin_command_invocations_total") .help("Counter for my plugin command invocations") .register();
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) {
// Increment your counter; commandCounter.inc(); // Do other stuff return true;
}
}