diff --git a/common/build.gradle.kts b/common/build.gradle.kts index ebeeaa1..d76f21f 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -12,6 +12,10 @@ minecraft { dependencies { compileOnlyApi(libs.jsr305) + + // Core libraries implementation(libs.bundles.prometheus) - compileOnly(libs.bundles.common) + compileOnly(libs.bundles.forgeConfig) + // Extra mods + compileOnly(libs.cct.forge) // We don't ship a common mod jar. } diff --git a/common/src/main/java/cc/tweaked/prometheus/Config.java b/common/src/main/java/cc/tweaked/prometheus/Config.java index 8c4b02e..5307886 100644 --- a/common/src/main/java/cc/tweaked/prometheus/Config.java +++ b/common/src/main/java/cc/tweaked/prometheus/Config.java @@ -23,10 +23,12 @@ public final class Config { vanilla = configBuilder .comment("Whether to expose some metrics about the state of the vanilla server.") + .worldRestart() .define("vanilla", false); jvm = configBuilder .comment("Whether to expose some metrics about the state of the Java runtime.") + .worldRestart() .define("jvm", false); spec = configBuilder.build(); diff --git a/common/src/main/java/cc/tweaked/prometheus/ServerMetrics.java b/common/src/main/java/cc/tweaked/prometheus/ServerMetrics.java index 6c30db5..8fa5592 100644 --- a/common/src/main/java/cc/tweaked/prometheus/ServerMetrics.java +++ b/common/src/main/java/cc/tweaked/prometheus/ServerMetrics.java @@ -29,12 +29,19 @@ public static void onServerStart(MinecraftServer server) { var ticking = ServerMetrics.toTick = new ArrayList<>(); var registry = new MetricContext(server, collectorRegistry, ticking::add); - ComputerCollector.register(registry); - ComputerFieldCollector.register(registry); - ThreadGroupCollector.register(registry); + if (classExists("dan200.computercraft.api.ComputerCraftAPI")) { + ComputerCollector.register(registry); + ComputerFieldCollector.register(registry); + ThreadGroupCollector.register(registry); + } + if (Config.vanilla.get()) VanillaCollector.export(registry); if (Config.jvm.get()) DefaultExports.register(collectorRegistry); + if (!collectorRegistry.metricFamilySamples().hasMoreElements()) { + LOG.warn("Warning: no collectors are enabled! Check the configuration."); + } + try { ServerMetrics.server = new HTTPServer.Builder() .withHostname(Config.host.get()) @@ -61,4 +68,13 @@ public static void onServerStop() { public static void onServerTick() { for (var action : toTick) action.run(); } + + private static boolean classExists(String name) { + try { + Class.forName(name, false, ServerMetrics.class.getClassLoader()); + return true; + } catch (ClassNotFoundException ignored) { + return false; + } + } } diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 7f2fc7d..39f9052 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -22,22 +22,18 @@ dependencies { }, ) - modImplementation(libs.bundles.fabric) + modImplementation(libs.fabric.loader) + modImplementation(libs.fabric.api) + // Core libraries implementation(libs.bundles.prometheus) + modImplementation(libs.bundles.forgeConfig) + // Extra mods + modImplementation(libs.cct.fabric) + include(libs.bundles.prometheus) + include(libs.bundles.forgeConfig) implementation(project(":common")) - -// implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1' -// -// implementation project(":common") -// -// modImplementation ("cc.tweaked:cc-tweaked-${minecraft_version}-fabric:${cct_version}") -// -// // IDK how Fabric config works (so much seems to be client-only??), so just copy CC:R. -// implementation 'com.electronwill.night-config:toml:3.6.5' -// include 'com.electronwill.night-config:core:3.6.5' -// include 'com.electronwill.night-config:toml:3.6.5' } loom { diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 09c2f70..2e5b03e 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -22,7 +22,9 @@ "fabricloader": ">=0.14", "fabric": "*", "minecraft": "1.19.x", - "java": ">=17", + "java": ">=17" + }, + "recommends": { "computercraft": "*" } } diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 0db1ddf..48cb63d 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -44,7 +44,9 @@ dependencies { compileOnly(project(":common")) + // Core libraries minecraftEmbed(libs.bundles.prometheus) + // Extra mods implementation(fg.deobf(libs.cct.forge.get())) } diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index b062253..43d3cd1 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -25,7 +25,7 @@ Hosts a Prometheus server with various ComputerCraft related statistics [[dependencies.ccprometheus]] modId="computercraft" - mandatory=true + mandatory=false versionRange="[1.102.0,)" ordering="NONE" side="BOTH" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2f96db7..598e3e9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -31,6 +31,7 @@ nightConfig-core = { module = "com.electronwill.night-config:core", version.ref nightConfig-toml = { module = "com.electronwill.night-config:toml", version.ref = "nightConfig" } prometheus-core = { module = "io.prometheus:simpleclient", version.ref = "prometheus" } +prometheus-common = { module = "io.prometheus:simpleclient_common", version.ref = "prometheus" } prometheus-server = { module = "io.prometheus:simpleclient_httpserver", version.ref = "prometheus" } prometheus-hotspot = { module = "io.prometheus:simpleclient_hotspot", version.ref = "prometheus" } # All the transitive deps of prometheus. @@ -54,10 +55,7 @@ shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" } [bundles] prometheus = [ - "prometheus-core", "prometheus-server", "prometheus-hotspot", + "prometheus-core", "prometheus-common", "prometheus-server", "prometheus-hotspot", "prometheus-tracerCommon", "prometheus-tracerOtel", "prometheus-tracerOtelAgent" ] - -common = ["cct-forge", "forgeConfig", "nightConfig-core", "nightConfig-toml"] -fabric = ["fabric-loader", "fabric-api", "cct-fabric", "forgeConfig", "nightConfig-core", "nightConfig-toml"] -forge = ["cct-forge"] +forgeConfig = ["forgeConfig", "nightConfig-core", "nightConfig-toml"]