Compare commits
10 commits
07e2f576d1
...
d5e8f412d7
Author | SHA1 | Date | |
---|---|---|---|
|
d5e8f412d7 | ||
|
a74174a585 | ||
|
32be73bab8 | ||
|
810e225915 | ||
|
0045d53a51 | ||
|
8e8753da68 | ||
|
2806a25203 | ||
|
ca94f79373 | ||
|
457c80de38 | ||
|
10362e5517 |
15 changed files with 94 additions and 55 deletions
33
README.md
33
README.md
|
@ -5,7 +5,7 @@
|
|||
|
||||
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).
|
||||
|
||||
| Prometheus name | Description | Config property | Collected by |
|
||||
|---------------------------------|----------------------------------------------------|------------------------------|----------------|
|
||||
| `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_mspt` | Count of milliseconds per tick (MSPT) | `enable-mspt` | 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_entities` | Amount of currently loaded entities on your server | `enable-entities` | FabricExporter |
|
||||
| `minecraft_handshakes` | Count of handshake requests | `enable-handshakes` | FabricExporter |
|
||||
| Prometheus name | Description | Config property | Collected by |
|
||||
|---------------------------------|-----------------------------------------------------------------------------------------|------------------------------|-------------------|
|
||||
| `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_mspt` | Count of milliseconds per tick (MSPT) | `enable-mspt` | 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_entities` | Amount of currently loaded entities on your server | `enable-entities` | 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
|
||||
|
||||
|
@ -40,7 +41,7 @@ To use this mod you should have at least Fabric server and Prometheus installed.
|
|||
|
||||
### 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.
|
||||
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.
|
||||
|
@ -81,11 +82,11 @@ In this file you can see some general settings and metrics settings.
|
|||
|
||||
### General settings
|
||||
|
||||
| Property | Description | Default value |
|
||||
| -------- | ----------- | ------------- |
|
||||
| `server-port` | Port on what the web server will listen for requests | `25585` |
|
||||
| `update-interval` | Interval between gauge metrics updates in milliseconds | `1000` |
|
||||
| `use-spark` | If set to `false`, FabricExporter will be independent from Spark | `true` |
|
||||
| Property | Description | Default value |
|
||||
|-------------------|------------------------------------------------------------------|---------------|
|
||||
| `server-port` | Port on what the web server will listen for requests | `25585` |
|
||||
| `update-interval` | Interval between gauge metrics updates in milliseconds | `1000` |
|
||||
| `use-spark` | If set to `false`, FabricExporter will be independent from Spark | `true` |
|
||||
|
||||
### Metrics settings
|
||||
|
||||
|
|
51
build.gradle
51
build.gradle
|
@ -1,9 +1,8 @@
|
|||
import com.modrinth.minotaur.TaskModrinthUpload
|
||||
import net.fabricmc.loom.task.RemapJarTask
|
||||
|
||||
plugins {
|
||||
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 'maven-publish'
|
||||
}
|
||||
|
@ -14,8 +13,6 @@ repositories {
|
|||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.github.johnrengelman.shadow'
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
|
@ -36,68 +33,76 @@ 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"
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
inputs.property 'version', project.version
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include "fabric.mod.json"
|
||||
expand "version": project.version
|
||||
include 'fabric.mod.json'
|
||||
expand 'version': project.version
|
||||
}
|
||||
|
||||
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
|
||||
// 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
|
||||
tasks.withType(JavaCompile) {
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this task, sources will not be generated.
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = "sources"
|
||||
tasks.register('sourcesJar', Jar) {
|
||||
dependsOn classes
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
jar {
|
||||
from "LICENSE"
|
||||
from 'LICENSE'
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveClassifier = "shaded-dev"
|
||||
archiveClassifier = 'shaded-dev'
|
||||
|
||||
dependencies {
|
||||
include dependency("io.prometheus:simpleclient:${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_hotspot:${project.prometheus_version}")
|
||||
}
|
||||
}
|
||||
|
||||
task remapShadowJar(type: RemapJarTask, dependsOn: shadowJar) {
|
||||
tasks.register('remapShadowJar', RemapJarTask) {
|
||||
dependsOn shadowJar
|
||||
input = shadowJar.archiveFile
|
||||
archiveFileName = shadowJar.archiveFileName.get().replaceAll("-shaded-dev\\.jar\$", ".jar")
|
||||
archiveFileName = shadowJar.archiveFileName.get().replaceAll('-shaded-dev\\.jar\$', '.jar')
|
||||
addNestedDependencies = true
|
||||
}
|
||||
|
||||
assemble.dependsOn(remapShadowJar)
|
||||
|
||||
task publishModrinth(type: TaskModrinthUpload, dependsOn: remapShadowJar) {
|
||||
onlyIf { System.getenv("MODRINTH_TOKEN") }
|
||||
|
||||
token = System.getenv("MODRINTH_TOKEN")
|
||||
modrinth {
|
||||
token = System.getenv('MODRINTH_TOKEN')
|
||||
projectId = 'dbVXHSlv'
|
||||
versionNumber = project.mod_version
|
||||
versionType = 'release'
|
||||
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)
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
org.gradle.jvmargs=-Xmx2G
|
||||
# Fabric Properties
|
||||
# check these on https://modmuss50.me/fabric.html
|
||||
minecraft_version=1.19.3
|
||||
yarn_mappings=1.19.3+build.5
|
||||
loader_version=0.14.13
|
||||
minecraft_version=1.20.1
|
||||
yarn_mappings=1.20.1+build.2
|
||||
loader_version=0.14.21
|
||||
# Mod Properties
|
||||
mod_version=1.0.8
|
||||
mod_version=1.0.10
|
||||
maven_group=ru.ruscalworld
|
||||
archives_base_name=fabricexporter
|
||||
# Dependencies
|
||||
# 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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -4,7 +4,14 @@ import io.prometheus.client.Collector;
|
|||
import io.prometheus.client.Counter;
|
||||
import io.prometheus.client.SimpleCollector;
|
||||
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.HashMap;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.misc.DoubleAverageInfo;
|
|
@ -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.SparkProvider;
|
||||
import ru.ruscalworld.fabricexporter.metrics.Metric;
|
||||
|
||||
public abstract class SparkMetric extends Metric {
|
||||
public SparkMetric(String name, String help, String... labels) {
|
|
@ -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.types.DoubleStatistic;
|
|
@ -1,4 +1,4 @@
|
|||
package ru.ruscalworld.fabricexporter.metrics;
|
||||
package ru.ruscalworld.fabricexporter.metrics.world;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
|
@ -7,6 +7,7 @@ import net.minecraft.server.world.ServerWorld;
|
|||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.TypeFilter;
|
||||
import ru.ruscalworld.fabricexporter.FabricExporter;
|
||||
import ru.ruscalworld.fabricexporter.metrics.Metric;
|
||||
import ru.ruscalworld.fabricexporter.util.TextUtil;
|
||||
|
||||
import java.util.HashMap;
|
|
@ -1,7 +1,8 @@
|
|||
package ru.ruscalworld.fabricexporter.metrics;
|
||||
package ru.ruscalworld.fabricexporter.metrics.world;
|
||||
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import ru.ruscalworld.fabricexporter.FabricExporter;
|
||||
import ru.ruscalworld.fabricexporter.metrics.Metric;
|
||||
import ru.ruscalworld.fabricexporter.util.TextUtil;
|
||||
|
||||
public class LoadedChunks extends Metric {
|
|
@ -1,7 +1,8 @@
|
|||
package ru.ruscalworld.fabricexporter.metrics;
|
||||
package ru.ruscalworld.fabricexporter.metrics.world;
|
||||
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import ru.ruscalworld.fabricexporter.FabricExporter;
|
||||
import ru.ruscalworld.fabricexporter.metrics.Metric;
|
||||
import ru.ruscalworld.fabricexporter.util.TextUtil;
|
||||
|
||||
public class OnlinePlayers extends Metric {
|
|
@ -1,7 +1,8 @@
|
|||
package ru.ruscalworld.fabricexporter.metrics;
|
||||
package ru.ruscalworld.fabricexporter.metrics.world;
|
||||
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import ru.ruscalworld.fabricexporter.FabricExporter;
|
||||
import ru.ruscalworld.fabricexporter.metrics.Metric;
|
||||
import ru.ruscalworld.fabricexporter.util.TextUtil;
|
||||
|
||||
public class TotalLoadedChunks extends Metric {
|
|
@ -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
|
||||
enable-handshakes=true
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.13",
|
||||
"minecraft": ">=1.19.3",
|
||||
"minecraft": ">=1.20.1",
|
||||
"fabric": "*"
|
||||
},
|
||||
"recommends": {
|
||||
|
|
Loading…
Reference in a new issue