Spark Web API
This is a compact plugin that creates a web interface for interacting with Spark through an API.
The plugin is specifically designed for Paper servers. The source code is available on GitHub where it can be adapted for other mod loaders.
Installation
To start working, you need to install Spark on your Paper server. It's important to note that even with Minecraft versions 1.21 and newer where Spark functionality is built-in by default, you'll still need a separate plugin version.
After that, you can proceed with installing Spark Web API. It's recommended to download the JAR file version with the "-all" mark in the name.
When starting the server, you need to activate a special system parameter:
java -Dpaper.preferSparkPlugin=true -jar paper-1.21-129.jar
Configuration Settings
When the server first loads with the installed plugin, a configuration file is automatically created. In it you can configure:
- Web server port number
- Activation of various API endpoints
- Additional response headers
Example configuration:
port: 3000
routes:
tps: true
mspt: true
sys_cpu: false
proc_cpu: false
gc: false
headers:
enabled: false
Available API Routes
Endpoint /api/tps
Provides information about TPS values over the last 10 seconds, 1 minute, 5 minutes, and 15 minutes.
Example response:
{
"tenSeconds": 19.999926688268733,
"oneMinute": 20.000035730063832,
"fiveMinutes": 20.00000458740105,
"fifteenMinutes": 19.94021043987079
}
Returns code 500 if data retrieval fails.
Endpoint /api/mspt
Returns MSPT metrics for 10 seconds and 1 minute with detailed statistics.
Example response:
{
"tenSeconds": {
"min": 6.523605,
"max": 2692.747083,
"mean": 66.92731750515465,
"median": 23.108289
},
"oneMinute": {
"min": 6.523605,
"max": 2692.747083,
"mean": 66.92731750515465,
"median": 23.108289
}
}
Endpoint /api/gc
Displays information about garbage collector operation with detailed statistics for different generations.
Example response:
{
"G1 Young Generation": {
"name": "G1 Young Generation",
"frequency": 22328,
"avgTime": 81,
"totalCollections": 3,
"totalTime": 243
},
"G1 Old Generation": {
"name": "G1 Old Generation",
"frequency": 0,
"avgTime": 0,
"totalCollections": 0,
"totalTime": 0
}
}
Endpoint /api/cpu/sys
Provides data about overall system CPU load as a percentage.
Example response:
{
"tenSeconds": 0.20461582280862525,
"oneMinute": 0.31800215079510524,
"fifteenMinutes": 0.39118254849183964
}
Endpoint /api/cpu/proc
Shows CPU load specifically from the Minecraft process.
Example response:
{
"tenSeconds": 0.025064927938294894,
"oneMinute": 0.030417615615548597,
"fifteenMinutes": 0.06684861042724896
}