Compare commits

..

No commits in common. "d5e8f412d7d9c42e70dc03457f1ea8d5b2b4806a" and "07e2f576d1e6586b7e25254c92af1358de05ed41" have entirely different histories.

15 changed files with 55 additions and 94 deletions

View file

@ -5,7 +5,7 @@
Fabric mod that adds a Prometheus exporter with general metrics of your server. Fabric mod that adds a Prometheus exporter with general metrics of your server.
![Grafana Dashboard](https://grafana.com/api/dashboards/14492/images/10444/image) ![Grafana Dashboard](https://img.share.superhub.xyz/2oiycx.png)
--- ---
@ -24,16 +24,15 @@ Here is a list of metrics that are collected by FabricExporter.
You can disable any of these metrics in [config](src/main/resources/config/exporter.properties). You can disable any of these metrics in [config](src/main/resources/config/exporter.properties).
| Prometheus name | Description | Config property | Collected by | | Prometheus name | Description | Config property | Collected by |
|---------------------------------|-----------------------------------------------------------------------------------------|------------------------------|-------------------| |---------------------------------|----------------------------------------------------|------------------------------|----------------|
| `minecraft_loaded_chunks` | Amount of currently loaded chunks on server | `enable-loaded-chunks` | Minecraft | | `minecraft_loaded_chunks` | Amount of currently loaded chunks on server | `enable-loaded-chunks` | Minecraft |
| `minecraft_total_loaded_chunks` | Amount of total loaded chunks on server | `enable-total-loaded-chunks` | Minecraft | | `minecraft_total_loaded_chunks` | Amount of total loaded chunks on server | `enable-total-loaded-chunks` | Minecraft |
| `minecraft_mspt` | Count of milliseconds per tick (MSPT) | `enable-mspt` | Spark | | `minecraft_mspt` | Count of milliseconds per tick (MSPT) | `enable-mspt` | Spark |
| `minecraft_tps` | Count of ticks per second (TPS) | `enable-tps` | Spark | | `minecraft_tps` | Count of ticks per second (TPS) | `enable-tps` | Spark |
| `minecraft_players_online` | Amount of currently online players on your server | `enable-players-online` | FabricExporter | | `minecraft_players_online` | Amount of currently online players on your server | `enable-players-online` | FabricExporter |
| `minecraft_entities` | Amount of currently loaded entities on your server | `enable-entities` | FabricExporter | | `minecraft_entities` | Amount of currently loaded entities on your server | `enable-entities` | FabricExporter |
| `minecraft_handshakes` | Count of handshake requests | `enable-handshakes` | FabricExporter | | `minecraft_handshakes` | Count of handshake requests | `enable-handshakes` | FabricExporter |
| `jvm_*` | JVM metrics collected by [Prometheus client](https://github.com/prometheus/client_java) | `export-jvm-metrics` | Prometheus client |
## Getting started ## Getting started
@ -41,7 +40,7 @@ To use this mod you should have at least Fabric server and Prometheus installed.
### Installing mod ### Installing mod
1. Download the mod from [Releases](https://github.com/ruscalworld/fabric-exporter/releases) page. 1. Download the mod from [Releases](https://github.com/RuscalWorld/FabricExporter/releases) page.
2. Drop downloaded mod jar to the `mods` folder. 2. Drop downloaded mod jar to the `mods` folder.
3. Start your server to generate config file. 3. Start your server to generate config file.
4. Open `config/exporter.properties`, ensure that `server-port` value is an open port that can be accessed by your Prometheus and change it if required. 4. Open `config/exporter.properties`, ensure that `server-port` value is an open port that can be accessed by your Prometheus and change it if required.
@ -82,11 +81,11 @@ In this file you can see some general settings and metrics settings.
### General settings ### General settings
| Property | Description | Default value | | Property | Description | Default value |
|-------------------|------------------------------------------------------------------|---------------| | -------- | ----------- | ------------- |
| `server-port` | Port on what the web server will listen for requests | `25585` | | `server-port` | Port on what the web server will listen for requests | `25585` |
| `update-interval` | Interval between gauge metrics updates in milliseconds | `1000` | | `update-interval` | Interval between gauge metrics updates in milliseconds | `1000` |
| `use-spark` | If set to `false`, FabricExporter will be independent from Spark | `true` | | `use-spark` | If set to `false`, FabricExporter will be independent from Spark | `true` |
### Metrics settings ### Metrics settings

View file

@ -1,8 +1,9 @@
import com.modrinth.minotaur.TaskModrinthUpload
import net.fabricmc.loom.task.RemapJarTask import net.fabricmc.loom.task.RemapJarTask
plugins { plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2' id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.modrinth.minotaur' version '2.+' id 'com.modrinth.minotaur' version '1.1.0'
id 'fabric-loom' version '0.12-SNAPSHOT' id 'fabric-loom' version '0.12-SNAPSHOT'
id 'maven-publish' id 'maven-publish'
} }
@ -13,6 +14,8 @@ repositories {
} }
} }
apply plugin: 'com.github.johnrengelman.shadow'
sourceCompatibility = JavaVersion.VERSION_17 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17
@ -33,76 +36,68 @@ dependencies {
// You may need to force-disable transitiveness on them. // You may need to force-disable transitiveness on them.
implementation "io.prometheus:simpleclient:${project.prometheus_version}" implementation "io.prometheus:simpleclient:${project.prometheus_version}"
implementation "io.prometheus:simpleclient_httpserver:${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" compileOnly "me.lucko:spark-api:0.1-SNAPSHOT"
} }
processResources { processResources {
inputs.property 'version', project.version inputs.property "version", project.version
duplicatesStrategy = DuplicatesStrategy.INCLUDE duplicatesStrategy = DuplicatesStrategy.INCLUDE
from(sourceSets.main.resources.srcDirs) { from(sourceSets.main.resources.srcDirs) {
include 'fabric.mod.json' include "fabric.mod.json"
expand 'version': project.version expand "version": project.version
} }
from(sourceSets.main.resources.srcDirs) { from(sourceSets.main.resources.srcDirs) {
exclude 'fabric.mod.json' exclude "fabric.mod.json"
} }
} }
// ensure that the encoding is set to UTF-8, no matter what the system default is // ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly // this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile).configureEach { tasks.withType(JavaCompile) {
options.encoding = "UTF-8" options.encoding = "UTF-8"
} }
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present. // if it is present.
// If you remove this task, sources will not be generated. // If you remove this task, sources will not be generated.
tasks.register('sourcesJar', Jar) { task sourcesJar(type: Jar, dependsOn: classes) {
dependsOn classes classifier = "sources"
from sourceSets.main.allSource from sourceSets.main.allSource
} }
jar { jar {
from 'LICENSE' from "LICENSE"
} }
shadowJar { shadowJar {
archiveClassifier = 'shaded-dev' archiveClassifier = "shaded-dev"
dependencies { dependencies {
include dependency("io.prometheus:simpleclient:${project.prometheus_version}") include dependency("io.prometheus:simpleclient:${project.prometheus_version}")
include dependency("io.prometheus:simpleclient_common:${project.prometheus_version}") include dependency("io.prometheus:simpleclient_common:${project.prometheus_version}")
include dependency("io.prometheus:simpleclient_httpserver:${project.prometheus_version}") include dependency("io.prometheus:simpleclient_httpserver:${project.prometheus_version}")
include dependency("io.prometheus:simpleclient_hotspot:${project.prometheus_version}")
} }
} }
tasks.register('remapShadowJar', RemapJarTask) { task remapShadowJar(type: RemapJarTask, dependsOn: shadowJar) {
dependsOn shadowJar
input = shadowJar.archiveFile input = shadowJar.archiveFile
archiveFileName = shadowJar.archiveFileName.get().replaceAll('-shaded-dev\\.jar\$', '.jar') archiveFileName = shadowJar.archiveFileName.get().replaceAll("-shaded-dev\\.jar\$", ".jar")
addNestedDependencies = true addNestedDependencies = true
} }
modrinth { assemble.dependsOn(remapShadowJar)
token = System.getenv('MODRINTH_TOKEN')
task publishModrinth(type: TaskModrinthUpload, dependsOn: remapShadowJar) {
onlyIf { System.getenv("MODRINTH_TOKEN") }
token = System.getenv("MODRINTH_TOKEN")
projectId = 'dbVXHSlv' projectId = 'dbVXHSlv'
versionNumber = project.mod_version versionNumber = project.mod_version
versionType = 'release'
uploadFile = remapShadowJar uploadFile = remapShadowJar
addGameVersion("1.19")
gameVersions.add(project.minecraft_version) addLoader('fabric')
loaders.add('fabric')
dependencies {
required.project 'fabric-api'
optional.project 'spark'
}
} }
assemble.dependsOn(remapShadowJar)

View file

@ -2,14 +2,14 @@
org.gradle.jvmargs=-Xmx2G org.gradle.jvmargs=-Xmx2G
# Fabric Properties # Fabric Properties
# check these on https://modmuss50.me/fabric.html # check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.1 minecraft_version=1.19.3
yarn_mappings=1.20.1+build.2 yarn_mappings=1.19.3+build.5
loader_version=0.14.21 loader_version=0.14.13
# Mod Properties # Mod Properties
mod_version=1.0.10 mod_version=1.0.8
maven_group=ru.ruscalworld maven_group=ru.ruscalworld
archives_base_name=fabricexporter archives_base_name=fabricexporter
# Dependencies # Dependencies
# check this on https://modmuss50.me/fabric.html # check this on https://modmuss50.me/fabric.html
fabric_version=0.83.1+1.20.1 fabric_version=0.73.0+1.19.3
prometheus_version=0.16.0 prometheus_version=0.16.0

View file

@ -1,7 +1,6 @@
package ru.ruscalworld.fabricexporter; package ru.ruscalworld.fabricexporter;
import io.prometheus.client.exporter.HTTPServer; import io.prometheus.client.exporter.HTTPServer;
import io.prometheus.client.hotspot.DefaultExports;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
@ -45,10 +44,6 @@ public class FabricExporter implements ModInitializer {
metricRegistry.registerDefault(); metricRegistry.registerDefault();
this.setMetricRegistry(metricRegistry); this.setMetricRegistry(metricRegistry);
if (config.shouldExportJvmDefaults()) {
DefaultExports.initialize();
}
ServerLifecycleEvents.SERVER_STARTING.register(this::setServer); ServerLifecycleEvents.SERVER_STARTING.register(this::setServer);
ServerLifecycleEvents.SERVER_STARTED.register(server -> { ServerLifecycleEvents.SERVER_STARTED.register(server -> {
try { try {

View file

@ -4,14 +4,7 @@ import io.prometheus.client.Collector;
import io.prometheus.client.Counter; import io.prometheus.client.Counter;
import io.prometheus.client.SimpleCollector; import io.prometheus.client.SimpleCollector;
import ru.ruscalworld.fabricexporter.config.MainConfig; import ru.ruscalworld.fabricexporter.config.MainConfig;
import ru.ruscalworld.fabricexporter.metrics.Metric; import ru.ruscalworld.fabricexporter.metrics.*;
import ru.ruscalworld.fabricexporter.metrics.spark.MillisPerTick;
import ru.ruscalworld.fabricexporter.metrics.spark.SparkMetric;
import ru.ruscalworld.fabricexporter.metrics.spark.TicksPerSecond;
import ru.ruscalworld.fabricexporter.metrics.world.Entities;
import ru.ruscalworld.fabricexporter.metrics.world.LoadedChunks;
import ru.ruscalworld.fabricexporter.metrics.world.OnlinePlayers;
import ru.ruscalworld.fabricexporter.metrics.world.TotalLoadedChunks;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;

View file

@ -8,7 +8,6 @@ public class MainConfig extends Config {
private int port; private int port;
private int updateInterval; private int updateInterval;
private boolean useSpark; private boolean useSpark;
private boolean exportJvmDefaults;
public MainConfig(String name) { public MainConfig(String name) {
super(name); super(name);
@ -25,8 +24,6 @@ public class MainConfig extends Config {
this.setUpdateInterval(ConvertUtil.intToStringOrDefault(updateIntervalString, 1000)); this.setUpdateInterval(ConvertUtil.intToStringOrDefault(updateIntervalString, 1000));
this.setShouldUseSpark(properties.getProperty("use-spark", "true").equalsIgnoreCase("true")); this.setShouldUseSpark(properties.getProperty("use-spark", "true").equalsIgnoreCase("true"));
this.setShouldExportJvmDefaults(properties.getProperty("export-default-jvm-metrics", "true").equalsIgnoreCase("true"));
} }
public int getPort() { public int getPort() {
@ -52,12 +49,4 @@ public class MainConfig extends Config {
public void setShouldUseSpark(boolean useSpark) { public void setShouldUseSpark(boolean useSpark) {
this.useSpark = useSpark; this.useSpark = useSpark;
} }
public boolean shouldExportJvmDefaults() {
return exportJvmDefaults;
}
public void setShouldExportJvmDefaults(boolean exportJvmDefaults) {
this.exportJvmDefaults = exportJvmDefaults;
}
} }

View file

@ -1,4 +1,4 @@
package ru.ruscalworld.fabricexporter.metrics.world; package ru.ruscalworld.fabricexporter.metrics;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
@ -7,7 +7,6 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.TypeFilter; import net.minecraft.util.TypeFilter;
import ru.ruscalworld.fabricexporter.FabricExporter; import ru.ruscalworld.fabricexporter.FabricExporter;
import ru.ruscalworld.fabricexporter.metrics.Metric;
import ru.ruscalworld.fabricexporter.util.TextUtil; import ru.ruscalworld.fabricexporter.util.TextUtil;
import java.util.HashMap; import java.util.HashMap;

View file

@ -1,8 +1,7 @@
package ru.ruscalworld.fabricexporter.metrics.world; package ru.ruscalworld.fabricexporter.metrics;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import ru.ruscalworld.fabricexporter.FabricExporter; import ru.ruscalworld.fabricexporter.FabricExporter;
import ru.ruscalworld.fabricexporter.metrics.Metric;
import ru.ruscalworld.fabricexporter.util.TextUtil; import ru.ruscalworld.fabricexporter.util.TextUtil;
public class LoadedChunks extends Metric { public class LoadedChunks extends Metric {

View file

@ -1,4 +1,4 @@
package ru.ruscalworld.fabricexporter.metrics.spark; package ru.ruscalworld.fabricexporter.metrics;
import me.lucko.spark.api.statistic.StatisticWindow; import me.lucko.spark.api.statistic.StatisticWindow;
import me.lucko.spark.api.statistic.misc.DoubleAverageInfo; import me.lucko.spark.api.statistic.misc.DoubleAverageInfo;

View file

@ -1,8 +1,7 @@
package ru.ruscalworld.fabricexporter.metrics.world; package ru.ruscalworld.fabricexporter.metrics;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import ru.ruscalworld.fabricexporter.FabricExporter; import ru.ruscalworld.fabricexporter.FabricExporter;
import ru.ruscalworld.fabricexporter.metrics.Metric;
import ru.ruscalworld.fabricexporter.util.TextUtil; import ru.ruscalworld.fabricexporter.util.TextUtil;
public class OnlinePlayers extends Metric { public class OnlinePlayers extends Metric {

View file

@ -1,8 +1,7 @@
package ru.ruscalworld.fabricexporter.metrics.spark; package ru.ruscalworld.fabricexporter.metrics;
import me.lucko.spark.api.Spark; import me.lucko.spark.api.Spark;
import me.lucko.spark.api.SparkProvider; import me.lucko.spark.api.SparkProvider;
import ru.ruscalworld.fabricexporter.metrics.Metric;
public abstract class SparkMetric extends Metric { public abstract class SparkMetric extends Metric {
public SparkMetric(String name, String help, String... labels) { public SparkMetric(String name, String help, String... labels) {

View file

@ -1,4 +1,4 @@
package ru.ruscalworld.fabricexporter.metrics.spark; package ru.ruscalworld.fabricexporter.metrics;
import me.lucko.spark.api.statistic.StatisticWindow; import me.lucko.spark.api.statistic.StatisticWindow;
import me.lucko.spark.api.statistic.types.DoubleStatistic; import me.lucko.spark.api.statistic.types.DoubleStatistic;

View file

@ -1,8 +1,7 @@
package ru.ruscalworld.fabricexporter.metrics.world; package ru.ruscalworld.fabricexporter.metrics;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import ru.ruscalworld.fabricexporter.FabricExporter; import ru.ruscalworld.fabricexporter.FabricExporter;
import ru.ruscalworld.fabricexporter.metrics.Metric;
import ru.ruscalworld.fabricexporter.util.TextUtil; import ru.ruscalworld.fabricexporter.util.TextUtil;
public class TotalLoadedChunks extends Metric { public class TotalLoadedChunks extends Metric {

View file

@ -1,4 +1,4 @@
# On which port Prometheus webserver should be started? # On which port webserver should be started?
# Default: 25585 # Default: 25585
server-port=25585 server-port=25585
@ -14,11 +14,6 @@ update-interval=1000
# Default: true # Default: true
use-spark=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 # 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 "-" # 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" # For example, if you want to disable "minecraft_players_online", you should set "enable-players-online" to "false"
@ -51,4 +46,4 @@ enable-entities=true
# Exports count of handshake requests # Exports count of handshake requests
# Collected by FabricExporter # Collected by FabricExporter
enable-handshakes=true enable-handshakes=true

View file

@ -22,7 +22,7 @@
], ],
"depends": { "depends": {
"fabricloader": ">=0.14.13", "fabricloader": ">=0.14.13",
"minecraft": ">=1.20.1", "minecraft": ">=1.19.3",
"fabric": "*" "fabric": "*"
}, },
"recommends": { "recommends": {