Compare commits
5
Commits
v1.0.2
..
58e692833e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58e692833e | ||
|
|
2648897197 | ||
|
|
7f48256f7d | ||
|
|
79a83d3c1c | ||
|
|
3be6e7e18c |
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM gradle:8.6-jdk21
|
FROM gradle:8.14-jdk21
|
||||||
|
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ http:
|
|||||||
metrics:
|
metrics:
|
||||||
enable_jvm: true
|
enable_jvm: true
|
||||||
enable_process: true
|
enable_process: true
|
||||||
|
entity_snapshot_interval_seconds: 15
|
||||||
movement:
|
movement:
|
||||||
count_block_changes_only: true
|
count_block_changes_only: true
|
||||||
```
|
```
|
||||||
@@ -77,7 +78,7 @@ The Gitea workflow expects these secrets/variables:
|
|||||||
|
|
||||||
## Metrics
|
## Metrics
|
||||||
|
|
||||||
Some metrics depend on server implementations (TPS/MSPT, player ping, tile entities). If a method is unavailable on your server build, those metrics are omitted.
|
Some metrics depend on server implementations (TPS/MSPT, player ping, tile entities). If a method is unavailable on your server build, those metrics are omitted. Entity and tile counts are updated on a periodic main-thread snapshot.
|
||||||
|
|
||||||
| Metric | Type | Labels | Description |
|
| Metric | Type | Labels | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.0-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright © 2015-2021 the original authors.
|
# Copyright © 2015 the original authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@@ -114,7 +114,6 @@ case "$( uname )" in #(
|
|||||||
NONSTOP* ) nonstop=true ;;
|
NONSTOP* ) nonstop=true ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH="\\\"\\\""
|
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
@@ -172,7 +171,6 @@ fi
|
|||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
if "$cygwin" || "$msys" ; then
|
if "$cygwin" || "$msys" ; then
|
||||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
|
||||||
|
|
||||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
@@ -212,7 +210,6 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
-classpath "$CLASSPATH" \
|
|
||||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-2
@@ -70,11 +70,10 @@ goto fail
|
|||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=
|
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ import java.net.InetSocketAddress;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
public final class PrometheusSpigotPlugin extends JavaPlugin {
|
public final class PrometheusSpigotPlugin extends JavaPlugin {
|
||||||
private HttpServer httpServer;
|
private HttpServer httpServer;
|
||||||
@@ -25,6 +27,7 @@ public final class PrometheusSpigotPlugin extends JavaPlugin {
|
|||||||
private MetricsRegistry metricsRegistry;
|
private MetricsRegistry metricsRegistry;
|
||||||
private String bearerToken;
|
private String bearerToken;
|
||||||
private boolean countBlockMovementOnly;
|
private boolean countBlockMovementOnly;
|
||||||
|
private BukkitTask snapshotTask;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -43,6 +46,8 @@ public final class PrometheusSpigotPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
metricsRegistry = new MetricsRegistry(getServer(), enableJvm, enableProcess);
|
metricsRegistry = new MetricsRegistry(getServer(), enableJvm, enableProcess);
|
||||||
|
|
||||||
|
scheduleSnapshotTask();
|
||||||
|
|
||||||
registerListeners();
|
registerListeners();
|
||||||
startHttpServer();
|
startHttpServer();
|
||||||
}
|
}
|
||||||
@@ -57,6 +62,10 @@ public final class PrometheusSpigotPlugin extends JavaPlugin {
|
|||||||
httpExecutor.shutdownNow();
|
httpExecutor.shutdownNow();
|
||||||
httpExecutor = null;
|
httpExecutor = null;
|
||||||
}
|
}
|
||||||
|
if (snapshotTask != null) {
|
||||||
|
snapshotTask.cancel();
|
||||||
|
snapshotTask = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerListeners() {
|
private void registerListeners() {
|
||||||
@@ -95,4 +104,12 @@ public final class PrometheusSpigotPlugin extends JavaPlugin {
|
|||||||
httpServer.start();
|
httpServer.start();
|
||||||
getLogger().info(String.format(Locale.ROOT, "Prometheus endpoint listening on http://%s:%d%s", bindAddress, port, path));
|
getLogger().info(String.format(Locale.ROOT, "Prometheus endpoint listening on http://%s:%d%s", bindAddress, port, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void scheduleSnapshotTask() {
|
||||||
|
int intervalSeconds = getConfig().getInt("metrics.entity_snapshot_interval_seconds", 15);
|
||||||
|
long intervalTicks = Math.max(20L, intervalSeconds * 20L);
|
||||||
|
|
||||||
|
metricsRegistry.refreshEntitySnapshots();
|
||||||
|
snapshotTask = Bukkit.getScheduler().runTaskTimer(this, metricsRegistry::refreshEntitySnapshots, intervalTicks, intervalTicks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.lang.management.MemoryUsage;
|
|||||||
import java.lang.management.ThreadMXBean;
|
import java.lang.management.ThreadMXBean;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -31,6 +32,8 @@ public final class MetricsRegistry {
|
|||||||
private final Method serverMsptMethod;
|
private final Method serverMsptMethod;
|
||||||
private final Method playerPingMethod;
|
private final Method playerPingMethod;
|
||||||
private final Method chunkTileEntitiesMethod;
|
private final Method chunkTileEntitiesMethod;
|
||||||
|
private volatile Map<String, Long> entityCountsSnapshot = Collections.emptyMap();
|
||||||
|
private volatile Map<String, Long> tileEntityCountsSnapshot = Collections.emptyMap();
|
||||||
|
|
||||||
private final LongAdder chatMessages = new LongAdder();
|
private final LongAdder chatMessages = new LongAdder();
|
||||||
private final LongAdder playerMovements = new LongAdder();
|
private final LongAdder playerMovements = new LongAdder();
|
||||||
@@ -120,6 +123,37 @@ public final class MetricsRegistry {
|
|||||||
pluginDisables.increment();
|
pluginDisables.increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refreshEntitySnapshots() {
|
||||||
|
Map<String, Long> entityCounts = new HashMap<>();
|
||||||
|
Map<String, Long> tileCounts = new HashMap<>();
|
||||||
|
|
||||||
|
for (var world : server.getWorlds()) {
|
||||||
|
for (Entity entity : world.getEntities()) {
|
||||||
|
EntityType type = entity.getType();
|
||||||
|
String label = normalizeLabel(type.name());
|
||||||
|
entityCounts.merge(label, 1L, Long::sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chunkTileEntitiesMethod != null) {
|
||||||
|
for (Chunk chunk : world.getLoadedChunks()) {
|
||||||
|
Object result = invoke(chunkTileEntitiesMethod, chunk);
|
||||||
|
if (!(result instanceof Object[] states)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Object state : states) {
|
||||||
|
if (state instanceof BlockState blockState) {
|
||||||
|
String label = normalizeLabel(blockState.getType().name());
|
||||||
|
tileCounts.merge(label, 1L, Long::sum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
entityCountsSnapshot = Collections.unmodifiableMap(entityCounts);
|
||||||
|
tileEntityCountsSnapshot = Collections.unmodifiableMap(tileCounts);
|
||||||
|
}
|
||||||
|
|
||||||
public String render() {
|
public String render() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
@@ -226,37 +260,14 @@ public final class MetricsRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void appendEntityMetrics(StringBuilder builder) {
|
private void appendEntityMetrics(StringBuilder builder) {
|
||||||
Map<String, Long> entityCounts = new HashMap<>();
|
appendLabeledGauge(builder, "spigot_entities_total", "Entities by type", "type", entityCountsSnapshot);
|
||||||
for (var world : server.getWorlds()) {
|
|
||||||
for (Entity entity : world.getEntities()) {
|
|
||||||
EntityType type = entity.getType();
|
|
||||||
String label = normalizeLabel(type.name());
|
|
||||||
entityCounts.merge(label, 1L, Long::sum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
appendLabeledGauge(builder, "spigot_entities_total", "Entities by type", "type", entityCounts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendTileEntityMetrics(StringBuilder builder) {
|
private void appendTileEntityMetrics(StringBuilder builder) {
|
||||||
if (chunkTileEntitiesMethod == null) {
|
if (chunkTileEntitiesMethod == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Map<String, Long> tileCounts = new HashMap<>();
|
appendLabeledGauge(builder, "spigot_tile_entities_total", "Tile entities by type", "type", tileEntityCountsSnapshot);
|
||||||
for (var world : server.getWorlds()) {
|
|
||||||
for (Chunk chunk : world.getLoadedChunks()) {
|
|
||||||
Object result = invoke(chunkTileEntitiesMethod, chunk);
|
|
||||||
if (!(result instanceof Object[] states)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (Object state : states) {
|
|
||||||
if (state instanceof BlockState blockState) {
|
|
||||||
String label = normalizeLabel(blockState.getType().name());
|
|
||||||
tileCounts.merge(label, 1L, Long::sum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
appendLabeledGauge(builder, "spigot_tile_entities_total", "Tile entities by type", "type", tileCounts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendPlayerPingMetrics(StringBuilder builder) {
|
private void appendPlayerPingMetrics(StringBuilder builder) {
|
||||||
|
|||||||
@@ -6,5 +6,6 @@ http:
|
|||||||
metrics:
|
metrics:
|
||||||
enable_jvm: true
|
enable_jvm: true
|
||||||
enable_process: true
|
enable_process: true
|
||||||
|
entity_snapshot_interval_seconds: 15
|
||||||
movement:
|
movement:
|
||||||
count_block_changes_only: true
|
count_block_changes_only: true
|
||||||
|
|||||||
Reference in New Issue
Block a user