Minecraft Prometheus Exporter
Minecraft Prometheus Exporter is a prometheus exporter for minecraft server that provide information about server tick time/tick rate. It make use of the ASM library to inject itself directly in the java class loader and modify the server to add data collections points. It therefor does not requires any mod/plugin loader.
Tested for minecraft 1.8.9 only
How to use
Build with:
./gradlew build
Start your minecraft server with the resulting jar as a javaagent like so:
/usr/lib/jvm/java-8-openjdk/bin/java -javaagent:mc_prom_exporter.jar -jar server.jar nogui
The file grafana.json provide a example of a grafana dash board like this one:
An example of docker-compose.yml and a prometheus.yml are provided in the docker_test folder.
Ho to Work with
jadx is a great tool for java reverse engineering.
JAVA_HOME="/usr/lib/jvm/java-21-openjdk" jadx -d server server.jar
ASM provide utility to print the byte code of classes.
(make sure to adapt the classpath syntax to the OS you are on)
To get the code of the MinecraftServer main class:
/usr/lib/jvm/java-21-openjdk/bin/java -cp "asm.jar:asm-util.jar:server.jar" org.objectweb.asm.util.Textifier net.minecraft.server.MinecraftServer
ASM also provide an ASMifier that print the ASM code needed to produce the byte code of the given Class. It is useful both for looking at the Class that you are modifying, and for generating injection instructions for you by ASMifying a similar class with your injection code already added.
/usr/lib/jvm/java-21-openjdk/bin/java -cp "asm.jar:asm-util.jar:server.jar" org.objectweb.asm.util.ASMifier net.minecraft.server.MinecraftServer
/usr/lib/jvm/java-21-openjdk/bin/java -cp "asm.jar:asm-util.jar:mc_prom_exporter.jar" org.objectweb.asm.util.ASMifier fr.xarus.mc_prom_exporter.Test
