diff --git a/build.gradle b/build.gradle index 7007665..9a9b3c5 100644 --- a/build.gradle +++ b/build.gradle @@ -36,6 +36,7 @@ dependencies { // You may need to force-disable transitiveness on them. implementation "io.prometheus:simpleclient:${project.prometheus_version}" implementation "io.prometheus:simpleclient_httpserver:${project.prometheus_version}" + implementation "io.prometheus:simpleclient_hotspot:${project.prometheus_version}" compileOnly "me.lucko:spark-api:0.1-SNAPSHOT" } diff --git a/src/main/java/ru/ruscalworld/fabricexporter/FabricExporter.java b/src/main/java/ru/ruscalworld/fabricexporter/FabricExporter.java index 26c63e2..c2236c5 100644 --- a/src/main/java/ru/ruscalworld/fabricexporter/FabricExporter.java +++ b/src/main/java/ru/ruscalworld/fabricexporter/FabricExporter.java @@ -1,6 +1,7 @@ package ru.ruscalworld.fabricexporter; import io.prometheus.client.exporter.HTTPServer; +import io.prometheus.client.hotspot.DefaultExports; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.loader.api.FabricLoader; @@ -44,6 +45,10 @@ public class FabricExporter implements ModInitializer { metricRegistry.registerDefault(); this.setMetricRegistry(metricRegistry); + if (config.shouldExportJvmDefaults()) { + DefaultExports.initialize(); + } + ServerLifecycleEvents.SERVER_STARTING.register(this::setServer); ServerLifecycleEvents.SERVER_STARTED.register(server -> { try { diff --git a/src/main/java/ru/ruscalworld/fabricexporter/config/MainConfig.java b/src/main/java/ru/ruscalworld/fabricexporter/config/MainConfig.java index 7f215cb..34e352d 100644 --- a/src/main/java/ru/ruscalworld/fabricexporter/config/MainConfig.java +++ b/src/main/java/ru/ruscalworld/fabricexporter/config/MainConfig.java @@ -8,6 +8,7 @@ public class MainConfig extends Config { private int port; private int updateInterval; private boolean useSpark; + private boolean exportJvmDefaults; public MainConfig(String name) { super(name); @@ -24,6 +25,8 @@ public class MainConfig extends Config { this.setUpdateInterval(ConvertUtil.intToStringOrDefault(updateIntervalString, 1000)); this.setShouldUseSpark(properties.getProperty("use-spark", "true").equalsIgnoreCase("true")); + + this.setShouldExportJvmDefaults(properties.getProperty("export-default-jvm-metrics", "true").equalsIgnoreCase("true")); } public int getPort() { @@ -49,4 +52,12 @@ public class MainConfig extends Config { public void setShouldUseSpark(boolean useSpark) { this.useSpark = useSpark; } + + public boolean shouldExportJvmDefaults() { + return exportJvmDefaults; + } + + public void setShouldExportJvmDefaults(boolean exportJvmDefaults) { + this.exportJvmDefaults = exportJvmDefaults; + } } diff --git a/src/main/resources/config/exporter.properties b/src/main/resources/config/exporter.properties index bed1a7c..ab65ba4 100644 --- a/src/main/resources/config/exporter.properties +++ b/src/main/resources/config/exporter.properties @@ -1,4 +1,4 @@ -# On which port webserver should be started? +# On which port Prometheus webserver should be started? # Default: 25585 server-port=25585 @@ -14,6 +14,11 @@ update-interval=1000 # Default: true use-spark=true +# Should FabricExporter register default Hotspot exports? +# This enables advanced metrics for JVM +# Default: true +export-default-jvm-metrics=true + # You can disable any metric that registered via MetricRegistry (all metrics by default) using the settings below # Names of properties consist of "enable" and metric name without prefix and "_" replaced with "-" # For example, if you want to disable "minecraft_players_online", you should set "enable-players-online" to "false" @@ -46,4 +51,4 @@ enable-entities=true # Exports count of handshake requests # Collected by FabricExporter -enable-handshakes=true \ No newline at end of file +enable-handshakes=true