Compare commits

...

10 commits

Author SHA1 Message Date
ruscalworld
d5e8f412d7
Bump version & update publishing 2023-06-20 17:34:40 +03:00
ruscalworld
a74174a585
Shadow simpleclient_hotspot 2023-06-20 17:34:16 +03:00
ruscalworld
32be73bab8
Update README 2023-06-20 17:01:03 +03:00
ruscalworld
810e225915
Add Hotspot metrics 2023-06-20 16:56:40 +03:00
ruscalworld
0045d53a51
Update project structure 2023-06-20 16:36:41 +03:00
ruscalworld
8e8753da68
Adjust build.gradle code style, use minecraft_version property in modrinth publish 2023-06-20 16:12:41 +03:00
ruscalworld
2806a25203
Migrate to 1.20.1 2023-06-20 16:06:23 +03:00
ruscalworld
ca94f79373
Fix game version 2023-06-20 15:49:29 +03:00
ruscalworld
457c80de38
Update Dashboard preview URL in README.md 2023-06-20 15:46:48 +03:00
ruscalworld
10362e5517 Bump version 2023-01-28 13:43:49 +03:00
15 changed files with 94 additions and 55 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://img.share.superhub.xyz/2oiycx.png) ![Grafana Dashboard](https://grafana.com/api/dashboards/14492/images/10444/image)
--- ---
@ -24,15 +24,16 @@ 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
@ -40,7 +41,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/FabricExporter/releases) page. 1. Download the mod from [Releases](https://github.com/ruscalworld/fabric-exporter/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.
@ -81,11 +82,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,9 +1,8 @@
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 '1.1.0' id 'com.modrinth.minotaur' version '2.+'
id 'fabric-loom' version '0.12-SNAPSHOT' id 'fabric-loom' version '0.12-SNAPSHOT'
id 'maven-publish' id 'maven-publish'
} }
@ -14,8 +13,6 @@ repositories {
} }
} }
apply plugin: 'com.github.johnrengelman.shadow'
sourceCompatibility = JavaVersion.VERSION_17 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17
@ -36,68 +33,76 @@ 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) { tasks.withType(JavaCompile).configureEach {
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.
task sourcesJar(type: Jar, dependsOn: classes) { tasks.register('sourcesJar', Jar) {
classifier = "sources" dependsOn classes
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}")
} }
} }
task remapShadowJar(type: RemapJarTask, dependsOn: shadowJar) { tasks.register('remapShadowJar', RemapJarTask) {
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
} }
assemble.dependsOn(remapShadowJar) modrinth {
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")
addLoader('fabric') gameVersions.add(project.minecraft_version)
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.19.3 minecraft_version=1.20.1
yarn_mappings=1.19.3+build.5 yarn_mappings=1.20.1+build.2
loader_version=0.14.13 loader_version=0.14.21
# Mod Properties # Mod Properties
mod_version=1.0.8 mod_version=1.0.10
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.73.0+1.19.3 fabric_version=0.83.1+1.20.1
prometheus_version=0.16.0 prometheus_version=0.16.0

View file

@ -1,6 +1,7 @@
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;
@ -44,6 +45,10 @@ 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,7 +4,14 @@ 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.*; import ru.ruscalworld.fabricexporter.metrics.Metric;
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,6 +8,7 @@ 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);
@ -24,6 +25,8 @@ 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() {
@ -49,4 +52,12 @@ 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; package ru.ruscalworld.fabricexporter.metrics.spark;
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,7 +1,8 @@
package ru.ruscalworld.fabricexporter.metrics; package ru.ruscalworld.fabricexporter.metrics.spark;
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; package ru.ruscalworld.fabricexporter.metrics.spark;
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,4 +1,4 @@
package ru.ruscalworld.fabricexporter.metrics; package ru.ruscalworld.fabricexporter.metrics.world;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
@ -7,6 +7,7 @@ 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,7 +1,8 @@
package ru.ruscalworld.fabricexporter.metrics; package ru.ruscalworld.fabricexporter.metrics.world;
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,7 +1,8 @@
package ru.ruscalworld.fabricexporter.metrics; package ru.ruscalworld.fabricexporter.metrics.world;
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,7 +1,8 @@
package ru.ruscalworld.fabricexporter.metrics; package ru.ruscalworld.fabricexporter.metrics.world;
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 webserver should be started? # On which port Prometheus webserver should be started?
# Default: 25585 # Default: 25585
server-port=25585 server-port=25585
@ -14,6 +14,11 @@ 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"

View file

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