Compare commits
36
Commits
3e9ce9c3c3
..
v1.4.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e0a435767 | ||
|
|
6ee2bbf7e8 | ||
|
|
02b5639666 | ||
|
|
f82dd6c311 | ||
|
|
5017887429 | ||
|
|
fa2aec3502 | ||
|
|
5d0bf94dff | ||
|
|
e91797d9ac | ||
|
|
6952ba6975 | ||
|
|
83b66ce262 | ||
|
|
1bad62513f | ||
|
|
50840bdfb7 | ||
|
|
f91d289d8a | ||
|
|
aca7a81ad3 | ||
|
|
dc539e83d1 | ||
|
|
ec07769ff8 | ||
|
|
b2558b8855 | ||
|
|
58e692833e | ||
|
|
2648897197 | ||
|
|
7f48256f7d | ||
|
|
79a83d3c1c | ||
|
|
2fee52e87d | ||
|
|
811cb7f8ca | ||
|
|
3be6e7e18c | ||
|
|
f7abb16e0e | ||
|
|
d244fe729d | ||
|
|
8184dee9fe | ||
|
|
9f26449863 | ||
|
|
ae7c2bdc83 | ||
|
|
5d01605df3 | ||
|
|
84abaf8914 | ||
|
|
f4682689d6 | ||
|
|
902ef5806c | ||
|
|
d4a61660c0 | ||
|
|
846e6311a0 | ||
|
|
3fc1e31fa8 |
@@ -0,0 +1,97 @@
|
|||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up Java
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: 21
|
||||||
|
|
||||||
|
- name: Set up Node
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 22.14.0
|
||||||
|
|
||||||
|
- name: Install Node dependencies
|
||||||
|
run: npm install
|
||||||
|
|
||||||
|
- name: Lint commits
|
||||||
|
run: |
|
||||||
|
if [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then
|
||||||
|
FROM=$(git rev-list --max-parents=0 HEAD)
|
||||||
|
else
|
||||||
|
FROM="${{ github.event.before }}"
|
||||||
|
fi
|
||||||
|
npx commitlint --from "$FROM" --to "${{ github.sha }}"
|
||||||
|
|
||||||
|
- name: Release version
|
||||||
|
env:
|
||||||
|
GIT_AUTHOR_NAME: "automation"
|
||||||
|
GIT_AUTHOR_EMAIL: "automation@local"
|
||||||
|
GIT_COMMITTER_NAME: "automation"
|
||||||
|
GIT_COMMITTER_EMAIL: "automation@local"
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
run: npx semantic-release
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: ./gradlew build
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: prometheus-spigot-jar
|
||||||
|
path: build/libs/*.jar
|
||||||
|
|
||||||
|
- name: Create release
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
GITEA_API: ${{ vars.GITEA_API_URL }}
|
||||||
|
GITEA_SERVER_URL: ${{ vars.GITEA_SERVER_URL }}
|
||||||
|
GITHUB_SERVER_URL: ${{ github.server_url }}
|
||||||
|
run: |
|
||||||
|
TAG=$(git describe --tags --exact-match 2>/dev/null || true)
|
||||||
|
if [ -z "$TAG" ]; then
|
||||||
|
echo "No release tag on HEAD; skipping release."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [ -z "$GITEA_API" ]; then
|
||||||
|
if [ -n "$GITEA_SERVER_URL" ]; then
|
||||||
|
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
|
||||||
|
VERSION=${TAG#v}
|
||||||
|
JAR_PATH=$(ls build/libs/*.jar | head -n 1)
|
||||||
|
RELEASE_RESPONSE=$(curl -sS -X POST \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
"${GITEA_API}/repos/${GITHUB_REPOSITORY}/releases" \
|
||||||
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"draft\":false,\"prerelease\":false}")
|
||||||
|
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
|
||||||
|
echo "Failed to create release."
|
||||||
|
echo "$RELEASE_RESPONSE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
curl -sS -X POST \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
--data-binary "@${JAR_PATH}" \
|
||||||
|
"${GITEA_API}/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=prometheus-spigot-${VERSION}.jar"
|
||||||
@@ -4,5 +4,6 @@
|
|||||||
.settings/
|
.settings/
|
||||||
build/
|
build/
|
||||||
out/
|
out/
|
||||||
|
node_modules/
|
||||||
*.iml
|
*.iml
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
+28
@@ -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}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM gradle:8.6-jdk21
|
FROM gradle:9.3-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
|
||||||
```
|
```
|
||||||
@@ -67,14 +68,23 @@ scrape_configs:
|
|||||||
credentials: "<bearer_token>"
|
credentials: "<bearer_token>"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## CI Release Notes
|
||||||
|
|
||||||
|
The Gitea workflow expects these secrets/variables:
|
||||||
|
|
||||||
|
- `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`.
|
||||||
|
- 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 |
|
||||||
@@ -83,6 +93,10 @@ 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_items_crafted_total | counter | material | Items crafted by 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 |
|
||||||
|
|||||||
+5
-1
@@ -3,7 +3,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.prometheus"
|
group = "com.prometheus"
|
||||||
version = "0.1.0"
|
version = project.findProperty("version")?.toString() ?: "0.1.0"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -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") {
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
extends: ["@commitlint/config-conventional"],
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
version=undefined
|
||||||
Vendored
BIN
Binary file not shown.
+7
@@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.0-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
@@ -0,0 +1,248 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015 the original authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
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.
|
||||||
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "$( uname )" in #(
|
||||||
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
|
Darwin* ) darwin=true ;; #(
|
||||||
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
|
NONSTOP* ) nonstop=true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
|
else
|
||||||
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD=java
|
||||||
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# 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
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
||||||
Vendored
+93
@@ -0,0 +1,93 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%"=="" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "prometheus-spigot",
|
||||||
|
"private": true,
|
||||||
|
"devDependencies": {
|
||||||
|
"@commitlint/cli": "^20.0.0",
|
||||||
|
"@commitlint/config-conventional": "^20.0.0",
|
||||||
|
"@semantic-release/exec": "^7.0.0",
|
||||||
|
"@semantic-release/git": "^10.0.1",
|
||||||
|
"semantic-release": "^25.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,19 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,25 @@
|
|||||||
|
package com.prometheus.spigot.listeners;
|
||||||
|
|
||||||
|
import com.prometheus.spigot.metrics.MetricsRegistry;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,16 @@ 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<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> 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 +74,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 +94,18 @@ 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 incrementPlayerDeath(EntityDamageEvent.DamageCause cause) {
|
public void incrementPlayerDeath(EntityDamageEvent.DamageCause cause) {
|
||||||
incrementLabeledCounter(deathsByCause, cause.name());
|
incrementLabeledCounter(deathsByCause, cause.name());
|
||||||
}
|
}
|
||||||
@@ -120,6 +144,47 @@ public final class MetricsRegistry {
|
|||||||
pluginDisables.increment();
|
pluginDisables.increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void incrementItemsCrafted(Material material) {
|
||||||
|
incrementLabeledCounter(itemsCraftedByMaterial, material.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
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 +199,17 @@ 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_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_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 +298,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