33 Commits
Author SHA1 Message Date
dmg 56549fe10a feat: add per-player placement and crafting metrics
Build / build (push) Successful in 2m0s
2026-01-28 00:05:29 -05:00
dmg 0e0a435767 feat: add per-player movement and block metrics
Build / build (push) Successful in 2m21s
2026-01-28 00:01:59 -05:00
dmg 6ee2bbf7e8 feat: add grafana dashboard
Build / build (push) Successful in 1m58s
2026-01-27 23:55:49 -05:00
dmg 02b5639666 docs: update metrics list
Build / build (push) Successful in 1m55s
2026-01-27 23:23:41 -05:00
dmg f82dd6c311 fix: restore spigot chat listener
Build / build (push) Successful in 1m51s
2026-01-27 23:16:04 -05:00
dmg 5017887429 fix: switch to paper async chat event
Build / build (push) Failing after 1m25s
2026-01-27 23:03:40 -05:00
dmg fa2aec3502 Merge pull request 'chore(deps): update dependency gradle to v9' (#4) from renovate/gradle-9.x into main
Build / build (push) Successful in 1m27s
Reviewed-on: #4
2026-01-28 03:58:59 +00:00
dmg 5d0bf94dff Merge branch 'main' into renovate/gradle-9.x 2026-01-28 03:57:37 +00:00
dmg e91797d9ac chore(ci): use node 22.14.0 for releases
Build / build (push) Successful in 2m1s
2026-01-27 22:55:49 -05:00
dmg 6952ba6975 Merge branch 'main' into renovate/gradle-9.x 2026-01-28 03:48:48 +00:00
dmg 83b66ce262 Merge pull request 'chore(deps): update devdependencies (major)' (#5) from renovate/major-devdependencies into main
Build / build (push) Failing after 2m33s
Reviewed-on: #5
2026-01-28 03:47:49 +00:00
dmg 1bad62513f Merge branch 'main' into renovate/major-devdependencies 2026-01-28 03:44:18 +00:00
dmg 50840bdfb7 Merge pull request 'chore(deps): update gradle docker tag to v9' (#6) from renovate/major-docker-images into main
Build / build (push) Successful in 3m0s
Reviewed-on: #6
2026-01-28 03:44:05 +00:00
dmg f91d289d8a Merge branch 'main' into renovate/major-docker-images 2026-01-28 03:42:15 +00:00
dmg aca7a81ad3 feat: track entity kills by player
Build / build (push) Successful in 1m45s
2026-01-27 22:41:32 -05:00
dmg dc539e83d1 feat: add block place and craft metrics
Build / build (push) Successful in 4m54s
2026-01-27 22:34:59 -05:00
Renovate Bot ec07769ff8 chore(deps): update gradle docker tag to v9 2026-01-23 06:02:53 +00:00
Renovate Bot b2558b8855 chore(deps): update devdependencies 2026-01-23 05:07:59 +00:00
Renovate Bot 58e692833e chore(deps): update dependency gradle to v9 2026-01-23 05:07:57 +00:00
dmg 2648897197 fix: snapshot entity metrics on main thread
Build / build (push) Successful in 3m0s
2026-01-22 23:47:55 -05:00
dmg 7f48256f7d Merge pull request 'chore(deps): update gradle docker tag to v8.14' (#3) from renovate/docker-images into main
Build / build (push) Successful in 4m25s
Reviewed-on: #3
2026-01-23 04:13:25 +00:00
dmg 79a83d3c1c Merge branch 'main' into renovate/docker-images 2026-01-23 04:13:08 +00:00
dmg 2fee52e87d Merge pull request 'chore(deps): update dependency gradle to v8.14.3' (#2) from renovate/all-minor-updates into main
Build / build (push) Successful in 3m18s
Reviewed-on: #2
2026-01-23 04:08:43 +00:00
dmg 811cb7f8ca Merge branch 'main' into renovate/all-minor-updates 2026-01-23 04:08:17 +00:00
Renovate Bot 3be6e7e18c chore(deps): update gradle docker tag to v8.14 2026-01-23 04:01:11 +00:00
Renovate Bot f7abb16e0e chore(deps): update dependency gradle to v8.14.3 2026-01-23 04:01:09 +00:00
dmg d244fe729d build: remove python dependency in release step
Build / build (push) Successful in 4m41s
2026-01-22 23:01:04 -05:00
dmg 8184dee9fe Merge pull request 'chore: Configure Renovate' (#1) from renovate/configure into main
Build / build (push) Failing after 2m14s
Reviewed-on: #1
2026-01-23 03:57:24 +00:00
dmg 9f26449863 Merge branch 'main' into renovate/configure 2026-01-23 03:57:08 +00:00
dmg ae7c2bdc83 build: version jar filename
Build / build (push) Successful in 2m21s
2026-01-22 22:52:24 -05:00
dmg 5d01605df3 build: align semantic release config
Build / build (push) Successful in 3m2s
2026-01-22 22:48:46 -05:00
Renovate Bot 84abaf8914 chore(deps): add renovate.json 2026-01-23 03:45:45 +00:00
dmg f4682689d6 build: add gitea api url fallback
Build / build (push) Successful in 3m10s
2026-01-22 22:42:07 -05:00
22 changed files with 1352 additions and 72 deletions
+15 -6
View File
@@ -23,7 +23,7 @@ jobs:
- name: Set up Node - name: Set up Node
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: 20 node-version: 22.14.0
- name: Install Node dependencies - name: Install Node dependencies
run: npm install run: npm install
@@ -59,6 +59,8 @@ jobs:
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
GITEA_API: ${{ vars.GITEA_API_URL }} GITEA_API: ${{ vars.GITEA_API_URL }}
GITEA_SERVER_URL: ${{ vars.GITEA_SERVER_URL }}
GITHUB_SERVER_URL: ${{ github.server_url }}
run: | run: |
TAG=$(git describe --tags --exact-match 2>/dev/null || true) TAG=$(git describe --tags --exact-match 2>/dev/null || true)
if [ -z "$TAG" ]; then if [ -z "$TAG" ]; then
@@ -66,19 +68,26 @@ jobs:
exit 0 exit 0
fi fi
if [ -z "$GITEA_API" ]; then if [ -z "$GITEA_API" ]; then
echo "GITEA_API_URL is not set in repo variables." if [ -n "$GITEA_SERVER_URL" ]; then
exit 1 GITEA_API="${GITEA_SERVER_URL}/api/v1"
elif [ -n "$GITHUB_SERVER_URL" ]; then
GITEA_API="${GITHUB_SERVER_URL}/api/v1"
else
echo "GITEA_API_URL is not set and server URL is unavailable."
exit 1
fi
fi fi
VERSION=${TAG#v} VERSION=${TAG#v}
JAR_PATH=$(ls build/libs/*.jar | head -n 1) JAR_PATH=$(ls build/libs/*.jar | head -n 1)
RELEASE_ID=$(curl -sS -X POST \ RELEASE_RESPONSE=$(curl -sS -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \ -H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
"${GITEA_API}/repos/${GITHUB_REPOSITORY}/releases" \ "${GITEA_API}/repos/${GITHUB_REPOSITORY}/releases" \
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"draft\":false,\"prerelease\":false}" \ -d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"draft\":false,\"prerelease\":false}")
| python -c "import sys, json; print(json.load(sys.stdin).get('id', ''))") RELEASE_ID=$(printf "%s" "$RELEASE_RESPONSE" | node -e "const fs=require('fs');const data=fs.readFileSync(0,'utf8');const json=JSON.parse(data);process.stdout.write(String(json.id||''));")
if [ -z "$RELEASE_ID" ]; then if [ -z "$RELEASE_ID" ]; then
echo "Failed to create release." echo "Failed to create release."
echo "$RELEASE_RESPONSE"
exit 1 exit 1
fi fi
curl -sS -X POST \ curl -sS -X POST \
+28
View File
@@ -0,0 +1,28 @@
{
"branches": ["main"],
"tagFormat": "v${version}",
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{ "type": "chore", "scope": "deps", "release": "patch" }
]
}
],
"@semantic-release/release-notes-generator",
[
"@semantic-release/exec",
{
"prepareCmd": "node -e \"const fs=require('fs');fs.writeFileSync('gradle.properties', 'version=' + process.env.RELEASE_VERSION + '\\n');\""
}
],
[
"@semantic-release/git",
{
"assets": ["gradle.properties"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
]
}
-23
View File
@@ -1,23 +0,0 @@
module.exports = {
branches: ["main"],
tagFormat: "v${version}",
plugins: [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/exec",
{
prepareCmd:
"node -e \"const fs=require('fs');fs.writeFileSync('gradle.properties', 'version=' + process.env.RELEASE_VERSION + '\\n');\"",
},
],
[
"@semantic-release/git",
{
assets: ["gradle.properties"],
message:
"chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
},
],
],
};
+1 -1
View File
@@ -1,4 +1,4 @@
FROM gradle:8.6-jdk21 FROM gradle:9.3-jdk21
WORKDIR /workspace WORKDIR /workspace
+10 -1
View File
@@ -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
``` ```
@@ -73,15 +74,17 @@ The Gitea workflow expects these secrets/variables:
- `GITEA_TOKEN`: built-in Actions token with repo write access for tags/releases. - `GITEA_TOKEN`: built-in Actions token with repo write access for tags/releases.
- `GITEA_API_URL`: API base URL, for example `https://git.garvis.dev/api/v1`. - `GITEA_API_URL`: API base URL, for example `https://git.garvis.dev/api/v1`.
- Optional fallback: `GITEA_SERVER_URL` or the runner `GITHUB_SERVER_URL` are used if the API URL is not set.
## 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 |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| spigot_chat_messages_total | counter | none | Total chat messages sent | | spigot_chat_messages_total | counter | none | Total chat messages sent |
| spigot_player_movements_total | counter | none | Total player movement events | | spigot_player_movements_total | counter | none | Total player movement events |
| spigot_player_movements_by_player_total | counter | player | Player movements by player |
| spigot_players_joined_total | counter | none | Total player joins | | spigot_players_joined_total | counter | none | Total player joins |
| spigot_players_quit_total | counter | none | Total player quits | | spigot_players_quit_total | counter | none | Total player quits |
| spigot_chunk_loads_total | counter | none | Total chunk load events | | spigot_chunk_loads_total | counter | none | Total chunk load events |
@@ -90,6 +93,12 @@ Some metrics depend on server implementations (TPS/MSPT, player ping, tile entit
| spigot_plugin_enable_total | counter | none | Total plugin enable events | | spigot_plugin_enable_total | counter | none | Total plugin enable events |
| spigot_plugin_disable_total | counter | none | Total plugin disable events | | spigot_plugin_disable_total | counter | none | Total plugin disable events |
| spigot_blocks_broken_total | counter | material | Blocks broken by material | | spigot_blocks_broken_total | counter | material | Blocks broken by material |
| spigot_blocks_broken_by_player_total | counter | player,material | Blocks broken by player and material |
| spigot_blocks_placed_total | counter | material | Blocks placed by material |
| spigot_blocks_placed_by_player_total | counter | player,material | Blocks placed by player and material |
| spigot_items_crafted_total | counter | material | Items crafted by material |
| spigot_items_crafted_by_player_total | counter | player,material | Items crafted by player and material |
| spigot_entities_killed_total | counter | entity,killer | Entities killed by player |
| spigot_player_deaths_total | counter | cause | Player deaths by cause | | spigot_player_deaths_total | counter | cause | Player deaths by cause |
| spigot_player_logins_failed_total | counter | reason | Failed player logins by reason | | spigot_player_logins_failed_total | counter | reason | Failed player logins by reason |
| spigot_commands_blocked_total | counter | command | Blocked commands by name | | spigot_commands_blocked_total | counter | command | Blocked commands by name |
+4
View File
@@ -24,6 +24,10 @@ tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8" options.encoding = "UTF-8"
} }
tasks.jar {
archiveFileName.set("prometheus-spigot-${project.version}.jar")
}
tasks.processResources { tasks.processResources {
filteringCharset = "UTF-8" filteringCharset = "UTF-8"
filesMatching("plugin.yml") { filesMatching("plugin.yml") {
Binary file not shown.
+1 -1
View File
@@ -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.6-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
Vendored
+7 -8
View File
@@ -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.
@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# SPDX-License-Identifier: Apache-2.0
#
############################################################################## ##############################################################################
# #
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@@ -84,7 +86,7 @@ done
# shellcheck disable=SC2034 # shellcheck disable=SC2034
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@@ -112,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;; NONSTOP* ) nonstop=true ;;
esac esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
@@ -170,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" )
@@ -203,15 +203,14 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command: # Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped. # and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line. # treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
org.gradle.wrapper.GradleWrapperMain \
"$@" "$@"
# Stop when "xargs" is not available. # Stop when "xargs" is not available.
Vendored
+3 -2
View File
@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and @rem See the License for the specific language governing permissions and
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off @if "%DEBUG%"=="" @echo off
@rem ########################################################################## @rem ##########################################################################
@@ -68,11 +70,10 @@ goto fail
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* "%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
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -2,10 +2,10 @@
"name": "prometheus-spigot", "name": "prometheus-spigot",
"private": true, "private": true,
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^19.5.0", "@commitlint/cli": "^20.0.0",
"@commitlint/config-conventional": "^19.5.0", "@commitlint/config-conventional": "^20.0.0",
"@semantic-release/exec": "^6.0.3", "@semantic-release/exec": "^7.0.0",
"@semantic-release/git": "^10.0.1", "@semantic-release/git": "^10.0.1",
"semantic-release": "^23.1.1" "semantic-release": "^25.0.0"
} }
} }
+3
View File
@@ -0,0 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}
@@ -2,11 +2,14 @@ package com.prometheus.spigot;
import com.prometheus.spigot.http.MetricsHttpHandler; import com.prometheus.spigot.http.MetricsHttpHandler;
import com.prometheus.spigot.listeners.BlockBreakListener; import com.prometheus.spigot.listeners.BlockBreakListener;
import com.prometheus.spigot.listeners.BlockPlaceListener;
import com.prometheus.spigot.listeners.ChatListener; import com.prometheus.spigot.listeners.ChatListener;
import com.prometheus.spigot.listeners.ChunkListener; import com.prometheus.spigot.listeners.ChunkListener;
import com.prometheus.spigot.listeners.CommandListener; import com.prometheus.spigot.listeners.CommandListener;
import com.prometheus.spigot.listeners.ConnectionListener; import com.prometheus.spigot.listeners.ConnectionListener;
import com.prometheus.spigot.listeners.CraftListener;
import com.prometheus.spigot.listeners.DeathListener; import com.prometheus.spigot.listeners.DeathListener;
import com.prometheus.spigot.listeners.EntityKillListener;
import com.prometheus.spigot.listeners.MoveListener; import com.prometheus.spigot.listeners.MoveListener;
import com.prometheus.spigot.listeners.PluginListener; import com.prometheus.spigot.listeners.PluginListener;
import com.prometheus.spigot.metrics.MetricsRegistry; import com.prometheus.spigot.metrics.MetricsRegistry;
@@ -17,7 +20,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 +30,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 +49,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,11 +65,16 @@ 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() {
var pluginManager = getServer().getPluginManager(); var pluginManager = getServer().getPluginManager();
pluginManager.registerEvents(new BlockBreakListener(metricsRegistry), this); pluginManager.registerEvents(new BlockBreakListener(metricsRegistry), this);
pluginManager.registerEvents(new BlockPlaceListener(metricsRegistry), this);
pluginManager.registerEvents(new DeathListener(metricsRegistry), this); pluginManager.registerEvents(new DeathListener(metricsRegistry), this);
pluginManager.registerEvents(new ChatListener(metricsRegistry), this); pluginManager.registerEvents(new ChatListener(metricsRegistry), this);
pluginManager.registerEvents(new MoveListener(metricsRegistry, countBlockMovementOnly), this); pluginManager.registerEvents(new MoveListener(metricsRegistry, countBlockMovementOnly), this);
@@ -69,6 +82,8 @@ public final class PrometheusSpigotPlugin extends JavaPlugin {
pluginManager.registerEvents(new CommandListener(metricsRegistry), this); pluginManager.registerEvents(new CommandListener(metricsRegistry), this);
pluginManager.registerEvents(new ChunkListener(metricsRegistry), this); pluginManager.registerEvents(new ChunkListener(metricsRegistry), this);
pluginManager.registerEvents(new PluginListener(metricsRegistry), this); pluginManager.registerEvents(new PluginListener(metricsRegistry), this);
pluginManager.registerEvents(new CraftListener(metricsRegistry), this);
pluginManager.registerEvents(new EntityKillListener(metricsRegistry), this);
} }
private void startHttpServer() { private void startHttpServer() {
@@ -95,4 +110,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);
}
} }
@@ -15,5 +15,6 @@ public final class BlockBreakListener implements Listener {
@EventHandler @EventHandler
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
registry.incrementBlocksBroken(event.getBlock().getType()); registry.incrementBlocksBroken(event.getBlock().getType());
registry.incrementBlocksBroken(event.getBlock().getType(), event.getPlayer().getName());
} }
} }
@@ -0,0 +1,20 @@
package com.prometheus.spigot.listeners;
import com.prometheus.spigot.metrics.MetricsRegistry;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
public final class BlockPlaceListener implements Listener {
private final MetricsRegistry registry;
public BlockPlaceListener(MetricsRegistry registry) {
this.registry = registry;
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
registry.incrementBlocksPlaced(event.getBlockPlaced().getType());
registry.incrementBlocksPlaced(event.getBlockPlaced().getType(), event.getPlayer().getName());
}
}
@@ -2,6 +2,7 @@ package com.prometheus.spigot.listeners;
import com.prometheus.spigot.metrics.MetricsRegistry; import com.prometheus.spigot.metrics.MetricsRegistry;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
@@ -12,7 +13,7 @@ public final class ChatListener implements Listener {
this.registry = registry; this.registry = registry;
} }
@EventHandler @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChat(AsyncPlayerChatEvent event) { public void onChat(AsyncPlayerChatEvent event) {
registry.incrementChatMessages(); registry.incrementChatMessages();
} }
@@ -0,0 +1,29 @@
package com.prometheus.spigot.listeners;
import com.prometheus.spigot.metrics.MetricsRegistry;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.inventory.ItemStack;
public final class CraftListener implements Listener {
private final MetricsRegistry registry;
public CraftListener(MetricsRegistry registry) {
this.registry = registry;
}
@EventHandler
public void onCraft(CraftItemEvent event) {
ItemStack result = event.getRecipe() != null ? event.getRecipe().getResult() : null;
if (result == null || result.getType() == Material.AIR) {
return;
}
registry.incrementItemsCrafted(result.getType());
if (event.getWhoClicked() instanceof Player player) {
registry.incrementItemsCrafted(result.getType(), player.getName());
}
}
}
@@ -0,0 +1,22 @@
package com.prometheus.spigot.listeners;
import com.prometheus.spigot.metrics.MetricsRegistry;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
public final class EntityKillListener implements Listener {
private final MetricsRegistry registry;
public EntityKillListener(MetricsRegistry registry) {
this.registry = registry;
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
Player killer = event.getEntity().getKiller();
String killerLabel = killer != null ? killer.getName() : "null";
registry.incrementEntityKill(event.getEntity().getType(), killerLabel);
}
}
@@ -20,6 +20,7 @@ public final class MoveListener implements Listener {
return; return;
} }
registry.incrementPlayerMovements(); registry.incrementPlayerMovements();
registry.incrementPlayerMovements(event.getPlayer().getName());
} }
private boolean hasChangedBlock(PlayerMoveEvent event) { private boolean hasChangedBlock(PlayerMoveEvent event) {
@@ -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();
@@ -41,11 +44,18 @@ public final class MetricsRegistry {
private final LongAdder chunkGenerations = new LongAdder(); private final LongAdder chunkGenerations = new LongAdder();
private final LongAdder pluginEnables = new LongAdder(); private final LongAdder pluginEnables = new LongAdder();
private final LongAdder pluginDisables = new LongAdder(); private final LongAdder pluginDisables = new LongAdder();
private final ConcurrentHashMap<String, LongAdder> blocksPlacedByMaterial = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, LongAdder> blocksBrokenByMaterial = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, LongAdder> blocksBrokenByMaterial = new ConcurrentHashMap<>();
private final ConcurrentHashMap<LabelPair, LongAdder> blocksBrokenByPlayerMaterial = new ConcurrentHashMap<>();
private final ConcurrentHashMap<LabelPair, LongAdder> blocksPlacedByPlayerMaterial = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, LongAdder> deathsByCause = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, LongAdder> deathsByCause = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, LongAdder> loginFailuresByReason = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, LongAdder> loginFailuresByReason = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, LongAdder> commandsBlocked = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, LongAdder> commandsBlocked = new ConcurrentHashMap<>();
private final ConcurrentHashMap<LabelPair, LongAdder> commandsExecuted = new ConcurrentHashMap<>(); private final ConcurrentHashMap<LabelPair, LongAdder> commandsExecuted = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, LongAdder> itemsCraftedByMaterial = new ConcurrentHashMap<>();
private final ConcurrentHashMap<LabelPair, LongAdder> itemsCraftedByPlayerMaterial = new ConcurrentHashMap<>();
private final ConcurrentHashMap<LabelPair, LongAdder> entityKills = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, LongAdder> playerMovementsByPlayer = new ConcurrentHashMap<>();
public MetricsRegistry(Server server, boolean enableJvm, boolean enableProcess) { public MetricsRegistry(Server server, boolean enableJvm, boolean enableProcess) {
this.server = server; this.server = server;
@@ -66,6 +76,10 @@ public final class MetricsRegistry {
playerMovements.increment(); playerMovements.increment();
} }
public void incrementPlayerMovements(String player) {
incrementLabeledCounter(playerMovementsByPlayer, player);
}
public void incrementPlayerJoins() { public void incrementPlayerJoins() {
playerJoins.increment(); playerJoins.increment();
} }
@@ -82,6 +96,26 @@ public final class MetricsRegistry {
incrementLabeledCounter(blocksBrokenByMaterial, material.name()); incrementLabeledCounter(blocksBrokenByMaterial, material.name());
} }
public void incrementBlocksBroken(Material material, String player) {
String normalizedMaterial = normalizeLabel(material.name());
String normalizedPlayer = normalizeLabel(player);
blocksBrokenByPlayerMaterial
.computeIfAbsent(new LabelPair(normalizedPlayer, normalizedMaterial), key -> new LongAdder())
.increment();
}
public void incrementBlocksPlaced(Material material) {
incrementLabeledCounter(blocksPlacedByMaterial, material.name());
}
public void incrementBlocksPlaced(Material material, String player) {
String normalizedMaterial = normalizeLabel(material.name());
String normalizedPlayer = normalizeLabel(player);
blocksPlacedByPlayerMaterial
.computeIfAbsent(new LabelPair(normalizedPlayer, normalizedMaterial), key -> new LongAdder())
.increment();
}
public void incrementPlayerDeath(EntityDamageEvent.DamageCause cause) { public void incrementPlayerDeath(EntityDamageEvent.DamageCause cause) {
incrementLabeledCounter(deathsByCause, cause.name()); incrementLabeledCounter(deathsByCause, cause.name());
} }
@@ -120,6 +154,55 @@ public final class MetricsRegistry {
pluginDisables.increment(); pluginDisables.increment();
} }
public void incrementItemsCrafted(Material material) {
incrementLabeledCounter(itemsCraftedByMaterial, material.name());
}
public void incrementItemsCrafted(Material material, String player) {
String normalizedMaterial = normalizeLabel(material.name());
String normalizedPlayer = normalizeLabel(player);
itemsCraftedByPlayerMaterial
.computeIfAbsent(new LabelPair(normalizedPlayer, normalizedMaterial), key -> new LongAdder())
.increment();
}
public void incrementEntityKill(EntityType entityType, String killer) {
String normalizedEntity = normalizeLabel(entityType.name());
String normalizedKiller = normalizeLabel(killer);
entityKills.computeIfAbsent(new LabelPair(normalizedEntity, normalizedKiller), key -> new LongAdder()).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();
@@ -134,10 +217,21 @@ public final class MetricsRegistry {
appendCounter(builder, "spigot_plugin_disable_total", "Total plugin disable events", pluginDisables.sum()); appendCounter(builder, "spigot_plugin_disable_total", "Total plugin disable events", pluginDisables.sum());
appendLabeledCounterAdder(builder, "spigot_blocks_broken_total", "Blocks broken by material", "material", blocksBrokenByMaterial); appendLabeledCounterAdder(builder, "spigot_blocks_broken_total", "Blocks broken by material", "material", blocksBrokenByMaterial);
appendLabeledCounterAdder(builder, "spigot_blocks_broken_by_player_total", "Blocks broken by player and material", "player",
"material", blocksBrokenByPlayerMaterial);
appendLabeledCounterAdder(builder, "spigot_blocks_placed_total", "Blocks placed by material", "material", blocksPlacedByMaterial);
appendLabeledCounterAdder(builder, "spigot_blocks_placed_by_player_total", "Blocks placed by player and material", "player",
"material", blocksPlacedByPlayerMaterial);
appendLabeledCounterAdder(builder, "spigot_player_deaths_total", "Player deaths by cause", "cause", deathsByCause); appendLabeledCounterAdder(builder, "spigot_player_deaths_total", "Player deaths by cause", "cause", deathsByCause);
appendLabeledCounterAdder(builder, "spigot_player_logins_failed_total", "Failed player logins by reason", "reason", loginFailuresByReason); appendLabeledCounterAdder(builder, "spigot_player_logins_failed_total", "Failed player logins by reason", "reason", loginFailuresByReason);
appendLabeledCounterAdder(builder, "spigot_commands_blocked_total", "Blocked commands by name", "command", commandsBlocked); appendLabeledCounterAdder(builder, "spigot_commands_blocked_total", "Blocked commands by name", "command", commandsBlocked);
appendLabeledCounterAdder(builder, "spigot_commands_executed_total", "Commands executed by source", "command", "source", commandsExecuted); appendLabeledCounterAdder(builder, "spigot_commands_executed_total", "Commands executed by source", "command", "source", commandsExecuted);
appendLabeledCounterAdder(builder, "spigot_items_crafted_total", "Items crafted by material", "material", itemsCraftedByMaterial);
appendLabeledCounterAdder(builder, "spigot_items_crafted_by_player_total", "Items crafted by player and material", "player",
"material", itemsCraftedByPlayerMaterial);
appendLabeledCounterAdder(builder, "spigot_entities_killed_total", "Entities killed by player", "entity", "killer", entityKills);
appendLabeledCounterAdder(builder, "spigot_player_movements_by_player_total", "Player movements by player", "player",
playerMovementsByPlayer);
appendGauge(builder, "spigot_players_online", "Online player count", server.getOnlinePlayers().size()); appendGauge(builder, "spigot_players_online", "Online player count", server.getOnlinePlayers().size());
appendGauge(builder, "spigot_players_max", "Max player slots", server.getMaxPlayers()); appendGauge(builder, "spigot_players_max", "Max player slots", server.getMaxPlayers());
@@ -226,37 +320,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) {
+1
View File
@@ -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