Stats providers and bStats
Started 2026-11-12. All seven phases are done: phases 1 to 6 are built on this branch, and the bStats maintainer reviewed it on 2026-11-17. Design describes the code as it now stands, after the review on 2026-11-12 and the maintainer review. What we know and Decisions keep what was found and settled when the plan was written, and Open questions lists what is not settled.
Goal
Report pseudonymous usage statistics to bStats as a proof of concept, built on a stats system that is not tied to bStats.
The server collects its numbers in one place. Providers read them and send them somewhere, the way Transport lets RakNet and NetherNet carry the same sessions. bStats is the first provider.
Requirements from the request and from the bStats maintainer:
- The server reports as a server implementation, to the
server-implementationendpoint, with most data sent as custom charts. - The bStats settings live in their own section of
config.json, with attribution. The maintainer agreed to this in place of a separatebStats.txt. - Operators can opt out. The submit delay and frequency match the reference implementations.
- The work stays on a branch until the maintainer has looked at it.
- Addons reach bStats later through feature detection in the scripting runtime. That is out of scope here, and the design must leave room for it.
What we know
Facts gathered on 2026-11-12.
bStats wire protocol
From MetricsBase.java and bstats-pmmp (src/Metrics.php, src/MetricsConfig.php, src/SubmitDataTask.php, src/charts/). Both repositories are MIT.
- Request:
POST https://bStats.org/api/v2/data/<platform>, body gzip-compressed JSON. - Headers:
Accept: application/json,Connection: close,Content-Encoding: gzip,Content-Type: application/json,User-Agent: Metrics-Service/1. Java also sendsContent-Length. - Payload: platform fields at the top level, then
serverUUID,metricsVersionand oneserviceobject holdingid(the service ID from bstats.org) andcustomCharts. metricsVersion: Java sends3.2.2-SNAPSHOT, the PHP class sends1.0.0. Which value a new implementation sends is a question for the maintainer.- Timing: one submit after a random 3 to 6 minutes, then a repeating submit that starts a further random 0 to 30 minutes later and runs every 30 minutes. Both sources warn that changing the delay or frequency, or removing the opt-out, gets a service banned.
- Opt-out:
enabledis checked before scheduling and again at every submit.
Each chart is {"chartId": "<id>", "data": {...}}. A chart with nothing to say is left out of customCharts, and a chart whose callback throws is skipped:
| Chart | data | Left out when |
|---|---|---|
SimplePie | {"value": "<string>"} | The value is empty |
SingleLineChart | {"value": <int>} | The value is 0 |
AdvancedPie | {"values": {key: int}} | Every entry is 0; zero entries are dropped |
MultiLineChart | {"values": {key: int}} | Same as AdvancedPie |
DrilldownPie | {"values": {key: {inner: int}}} | Every inner map is empty |
SimpleBarChart | {"values": {key: [int]}} | The map is empty |
AdvancedBarChart | {"values": {key: [int, ...]}} | Every list is empty |
Velocity as the server-implementation reference
From Metrics.java. Velocity is GPLv3, so we read it for behavior and copy no code from it.
- Platform:
server-implementation, service ID 4752. - Platform data: only
osName,osArch,osVersionandcoreCount. It sends no service data and nopluginVersion. - Charts:
playersandmanaged_servers(SingleLineChart),online_modeandvelocity_version(SimplePie),java_version(DrilldownPie,Java 21then the full version). - First run: when it creates the config, it logs that metrics are collected and how to opt out.
The bStats config file
From MetricsConfig.java.
- Keys:
enabled,server-uuid,log-errors,log-sent-data,log-response-status-text. - Header: six comment lines that explain what bStats collects and link to
https://bstats.org/docs/server-owners. - UUID: a random version 4 UUID, generated once. It identifies the server across restarts, so losing it counts the server twice.
- Location: the maintainer's note says the location cannot change after release without breaking backwards compatibility.
This repository
- Kernel modules:
Server.buildKernel()inpackages/prismarine/src/Server.tsregisters one module per manager. A module provides a service under a token frompackages/prismarine/src/modules/tokens.ts, opens I/O instart()and closes it instop(). - The pattern to mirror:
Transportinpackages/prismarine/src/network/transport/Transport.tsis an interface with several implementations, combined byMultiTransportand chosen by theenable-raknetandenable-nethernetconfig keys. - Config:
ConfigBuilderreads and writesconfig.jsonone key at a time, keeps comments, and writes a comment above a key the first time it persists its default. Keys can be paths, andworldsis already a nested section.Config.tsrenames old keys withconfig.rename. - Data on hand: player count from
SessionManager.getAllPlayers(),online-modeand the enabled transports fromConfig, software and Minecraft versions fromabout(), each player's device OS fromPlayer.device.os, and TPS from the ticker. - Build stamps:
.github/scripts/set-build-metadata.mjsstampsBUILD_TYPE(releaseornightly),BUILD_VERSIONandBUILD_FLAVORinto a built server. A server run from source has none of them. - Nothing exists yet: no stats, telemetry or bStats code, and no outbound HTTP client in
packages/prismarine. - No plugin loader:
docs/guide/extending.mdsays a plugin today is a program that embeds@jsprismarine/prismarine.
Design
Three parts
server state ──> StatsRegistry ──> StatsProvider (bStats)
(named metrics) StatsProvider (an embedder's, passed as statsProviders)Metrics. A metric is a name, a kind, a description, an optional unit and a read() function that returns the current value. The registry reads a metric only when a provider asks, so nothing runs per tick.
| Kind | Value | Example |
|---|---|---|
gauge | number | Players online |
label | string | Server version |
set | readonly string[] | Enabled transports |
distribution | Record<string, number> | Players per device platform |
breakdown | Record<string, Record<string, number>> | Players per release, then protocol |
A metric whose read() returns undefined is left out of the reading. The kinds describe the data, not a chart: the metrics are raw values, and a provider decides how to draw them. The description (Players online.) and the unit (players) are there for a provider that shows metrics to people. Names are snake_case and namespaced (jsprismarine:player_protocol), so an addon can register myaddon:something later without a new mechanism. ServerMetric in stats/serverMetrics.ts holds the server's eight names, and serverMetrics() builds the eight metrics from the config and the session manager.
Platform. Beside the metrics, a snapshot carries one platform object, the host as node:os describes it. It is the same for every provider, and a provider that needs another form maps the fields itself:
| Field | Source |
|---|---|
type | os.type(), such as Darwin |
release | os.release(), such as 23.5.0 |
version | os.version(), such as Windows 11 Pro |
arch | os.arch() |
coreCount | os.availableParallelism() |
memoryGb | os.totalmem(), rounded to whole GB |
Registry. StatsRegistry.register(metric) checks the name, refuses a duplicate and returns a function that removes the metric again. read(name) reads one metric, and snapshot() reads every metric once with the platform. A metric that throws is logged as a warning and left out. A module that registers a metric in its start() disposes it in its stop(), so a kernel restart registers it again.
Providers. A provider is the equivalent of a transport:
interface StatsProvider {
readonly id: string;
start(context: StatsProviderContext): Promise<void> | void;
stop(): Promise<void> | void;
}The context holds three things: the registry, a logger scoped to the provider's id, and setTimer, an unreferenced setTimeout that returns a cancel function. A provider owns its schedule, because schedules differ: bStats dictates one, and a scrape endpoint would have none. Anything else a provider needs, such as fetch or a random source, it takes in its own constructor, so the context stays the same for every provider. stop() may run while start() is still pending, and again when it returns, so it must be safe to call twice.
Two kernel modules. prismarine:stats provides the registry under statsToken in its register(), with the server's metrics in it, and does nothing on start or stop. prismarine:stats-providers depends on statsToken and starts the providers in order, then stops them in reverse. Server.buildKernel() registers the registry first and the providers last. The split lets any module depend on statsToken and register a metric in its own register() or start(), and the providers still start after every module the server registers, so their first reading has those metrics. A provider that throws on start or stop is logged and skipped.
Embedders. new Server({ statsProviders }) takes providers of the embedder's own. They run after the built-in bStats provider, start after it and stop before it. The package exports the types they need: StatsProvider, StatsProviderContext, StatsTimer, StatsRegistry, StatsSnapshot, StatsPlatform, the metric types, and ServerMetric.
The bStats provider
- Service:
service.tsexports the service name and ID as constants,JSPrismarineand35257, and nothing else in the code spells them. - Charts:
BSTATS_CHARTSincharts.tslists the custom charts. Each has a title, a description, its bstats.org settings and abuildfunction that composes the chart's data from a snapshot, so one chart can read several metrics (build_typereads the build type and the version) or none (memoryreads the platform). The table is the allowlist: a metric no chart reads never reaches bStats. - Chart IDs: chart names are
snake_case, and bStats chart IDs are camelCase.chartId()derives the ID (player_protocolbecomesplayerProtocol), so each name is written once. The IDs must match the charts created on the bstats.org service page. - Default charts: bStats fills
servers,coreCount,osArch,os,locationandlocationMapitself, and their IDs are fixed.chartId()rejects a name that maps onto one of these six. - OS fields: the platform's
type,releaseandversiongo out unchanged asnodeOsType,nodeOsReleaseandnodeOsVersion. bStats' data processor maps them to the names itsoschart uses for Java'sos.nameandos.version, so the mapping lives in one place for every Node.js client. - Payload:
nodeOsType,nodeOsRelease,nodeOsVersion,osArchandcoreCount, thenserverUUID,metricsVersion(0.1.0) andservice. bStats has no platform field for memory, somemoryGbgoes out as thememorychart. - Transport:
node:zlibgzip andfetchfrom the constructor options, with a 60 second timeout. bStats' Java client sets none, and bStats' proxy retries a request through short downtime before it answers. No new dependency. - Schedule: the reference timing, on the context's timer and the random source from the options.
- Settings read once per start. The provider reads its gate, the UUID and the logging switches when it starts, and nothing it reads can change while it runs:
/reloadstops the kernel, reads the config again and starts the provider anew. - Failure: a failed submit is dropped and logged only when
log-errorsis on. It never throws into the server. A429, which bStats answers when it already has a submit from this server in the 30-minute window, is not a failure. - Shutdown:
stop()cancels the next submit and aborts a request in flight.
Charts:
| Chart | bStats chart ID | Type | Built from |
|---|---|---|---|
players | players | SingleLineChart | The players gauge |
build_type | buildType | DrilldownPie | The build_type label, then the version label |
memory | memory | SimplePie | The platform's memoryGb, as 8 GB |
online_mode | onlineMode | SimplePie | The online_mode label |
transports | transports | AdvancedPie | The transports set, 1 per enabled transport |
player_platform | playerPlatform | AdvancedPie | The player_platform distribution |
player_protocol | playerProtocol | DrilldownPie | The player_protocol breakdown |
player_transport | playerTransport | AdvancedPie | The player_transport distribution |
Build type. buildType() in version.ts decides dev, nightly or release:
- A release or nightly executable carries the
BUILD_TYPEstamp from.github/scripts/set-build-metadata.mjs, and reports it. - The npm package has no stamp. Its
vite buildsetsBUILD_DISTwhen CI runs it, which is where the published package is built, and the version decides: a prerelease such as0.21.0-unstable-20261112121906isnightly, any other versionrelease. - A checkout is
dev, whether it runs from source or throughpnpm devandpnpm start, which load a package build made on that machine.
Player platforms are display names from DEVICE_OS_NAMES in serverMetrics.ts, such as Android, iOS and Nintendo Switch, one per BuildPlatform member. A value the client sends that is not a member counts as Unknown.
Charts to create on bstats.org
Create these as custom charts on the JSPrismarine service page. The ID has to match exactly. The title and the type-specific settings can change later.
The type-specific settings are the ones bStats stores per chart, read on 2026-11-12 from https://bstats.org/api/v1/plugins/4752/charts (Velocity):
- Single Line Chart: a line name, and a filter with a minimum and a maximum value.
- Simple Pie, Advanced Pie and Drilldown Pie: a filter with a list of values, a regex switch and a blacklist switch. An Advanced Pie and a Drilldown Pie also have a numeric max value. Every filter below is an allowlist, so blacklist stays off.
| ID | Title | Type | Line name | Max value | Filter |
|---|---|---|---|---|---|
players | Players Online | Single Line Chart | Players | Off | |
buildType | Build Type | Drilldown Pie | 1 | Values dev, nightly, release | |
memory | Memory | Simple Pie | Regex [0-9]{1,4} GB | ||
onlineMode | Online Mode | Simple Pie | Values online, offline | ||
transports | Enabled Transports | Advanced Pie | 1 | Values RakNet, NetherNet | |
playerPlatform | Player Platform | Advanced Pie | 1000 | Off | |
playerProtocol | Player Game Version | Drilldown Pie | 1000 | Regex [0-9]{1,2}\.[0-9]{1,3}(\.[0-9]{1,3}){0,2} | |
playerTransport | Player Transport | Advanced Pie | 1000 | Values RakNet, NetherNet |
- Filters keep made-up values out. Anybody can post to the endpoint, so a chart with a closed set of values gets an allowlist. The provider has to send exactly these strings, and phase 2 tests that it does.
playerPlatformhas no filter, because device names grow with the game.- An Advanced Pie and a Drilldown Pie take a numeric max value, the most one entry may count.
buildTypesends one inner entry with the value 1, andtransportssends 1 per enabled transport, so their max is 1. The player charts send player counts, so their max is the most players one server may plausibly report, 1000 here. Velocity'sjava_versionhas it at 0, which this plan reads as no limit. - No chart needs an axis label. That setting belongs to bar charts and maps, and none of these is one.
The default charts already exist, and neither their IDs nor their types can change. Velocity's settings for them are shown for reference:
| ID | Type | Filled from | Velocity's setting |
|---|---|---|---|
servers | Single Line Chart | One count per reporting server | Line name Servers |
coreCount | Simple Pie | The coreCount platform field | Regex filter ([0-9]){1,2} |
osArch | Simple Pie | The osArch platform field | Filter off |
os | Drilldown Pie | The OS fields, mapped by bStats | Filter off |
location | Simple Pie | The address the request comes from | Filter off |
Velocity also has a default locationMap chart, a Simple Map with the value name Servers.
Config
A stats section in config.json with one entry per provider, and the server UUID in a file of its own, server-uuid.txt in the data directory:
{
"stats": {
// This server sends pseudonymous usage statistics, such as the player count and ...
// Learn more here: https://bstats.org/docs/server-owners
"bstats": {
"enabled": true,
"log-errors": false,
"log-sent-data": false,
"log-response-status-text": false
}
}
}- The server UUID belongs to the server, not to bStats. It is a random version 4 UUID generated on the first start that reports, and bStats sends it as
serverUUID. Anything else that needs to tell one server from another can use it later. It stays out ofconfig.json, so a config copied from a template or mounted read-only, such as from a Kubernetes ConfigMap, neither shares a UUID with another server nor loses its own. - One section per provider under
stats, with the bStats header text as the comment abovebstatsand the same key names asbStats.txt. A second provider adds a sibling, and addons can later read the same bStats settings through the runtime. - An unwritable UUID file stops the provider. A UUID that changes every restart would inflate the server count. A config that cannot take the
stats.bstatssection stops it too, since the section and its comment are how the operator learns about reporting. - The config fails closed. A file with no
stats.bstatssection gets one, with bStats on. Once the section exists, bStats reports only for a literalenabled: true. Astatsorstats.bstatsthat is not an object, or anenabledthat is missing, misspelled or not a boolean, turns it off with a warning naming the key, and the file is left as it is. A logging switch that is missing is written with its default. - The paths are fixed once released. If one ever has to move,
config.renamecarries the value over. - The first run logs a notice on the start that writes the
stats.bstatssection, when that start reports, naming bStats and the key that turns it off. JSP_BSTATSturns bStats off for containers.0,false,offandnoturn it off.1,true,onandyesleave the decision to the config, as an unset variable does. Case does not matter, and any other value turns bStats off with a warning. It belongs to the bStats provider. The stats system has no switch of its own yet, since bStats is its only provider.- A set
CIturns bStats off, as every CI service sets it, and so does the Vitest test runner.bstatsOffReason()inserverBStats.tschecks, in order: the test runner,CI,JSP_BSTATS, a config problem, andenabled: false.
Where the code lives
packages/prismarine/src/stats/:StatsRegistry, the metric types,StatsPlatform,StatsProvider, andserverMetrics.tswith the server's metrics and their names.packages/prismarine/src/serverUuid.ts: reads and writes the server UUID file.packages/prismarine/src/stats/bstats/:service.ts(name and ID),charts.ts,payload.ts,BStatsProvider.ts(schedule and submit) andserverBStats.ts(the gate and the notice for a server).packages/prismarine/src/modules/stats.ts: the two kernel modules, andstatsTokenintokens.ts.
Every server reports by default, whether @jsprismarine/server starts it or a program embeds @jsprismarine/prismarine: Server.buildKernel() registers the stats module with the bStats provider. Three things keep that honest:
- The notice is logged on the start that writes the section, when it reports, and names the config key that turns it off.
- The comment above
stats.bstatsinconfig.jsonsays what is sent and how to opt out. - Tests never send. The provider does not start under Vitest, with
CIset or withJSP_BSTATS=0, and itsfetchis a constructor option, so a unit test hands it a stub. The client e2e server and the executable smoke test setJSP_BSTATS=0.
The bStats code lives inside stats, which lives inside prismarine, and stays out of the public barrel. The barrel exports the stats types an embedder needs, not the bStats provider. bStats may get its own package later.
Addons, later
The maintainer's note says plugin support needs changes on bStats' end, so this plan only keeps the door open:
- Metric names are namespaced, so an addon registers its own.
- The bStats provider can grow from one
serviceto several without changing the registry. - The scripting runtime exposes a module that an addon feature-detects. Removing bStats removes the module, and the addon's check fails cleanly.
Testing
Every test drives the real code with a manual timer, fixed random values and a stub fetch. No test sends a request or asserts a duration.
- Registry: a snapshot reads each metric once, a throwing metric is left out, and a disposed metric is gone.
- Charts: each chart type produces the shape in the table above and is left out under its rule.
- Chart IDs: every mapped metric name becomes its camelCase chart ID, and a name that maps onto a default chart ID is rejected.
- Payload: the stub
fetchreceives the URL, the headers and a gzip body that decodes to the expected JSON. - Schedule: with fixed random values, submits happen at the first delay, at the second, and every 30 minutes after, and the delays stay inside 3 to 6 and 0 to 30 minutes at both extremes.
- Opt-out:
enabled: false, a malformedenabled, eachJSP_BSTATSoff value and an unknown one, a setCI, a Vitest run, an unwritable config and an unwritable UUID file each produce zero calls tofetch. - OS: the payload carries
node:os's type, release and version unchanged, and noosNameorosVersion. - Notice: the first start logs it once, and a second start with the section present logs nothing.
- Config: a first start writes the
stats.bstatssection with its comment and no UUID. - UUID: a first start writes the UUID file, a second start reads the same UUID, a malformed file gets a fresh one, and a directory that refuses the file leaves no UUID.
- Build type: a server with no build stamp reports
dev, a stamped one reports itsBUILD_TYPE, and a package build reportsnightlyfor a prerelease version andreleaseotherwise. - Lifecycle:
stop()leaves no pending timer, and a restart of the kernel schedules once.
Phases
Each phase is one delegated task and one or more local commits. A phase starts from the branch as the phase before it left it, reads this plan first, and ends with its own tests, pnpm run typecheck, pnpm run lint and pnpm exec vitest run --since-last-run passing. Tick a phase off here when it lands.
| Phase | Depends on | Can run beside |
|---|---|---|
| 1 | ||
| 2 | 1 | 3 |
| 3 | 2 | |
| 4 | 1, 2, 3 | |
| 5 | 4 | |
| 6 | 5 | |
| 7 | 6 |
Phase 1: the stats seam
Notes from the build, as the review left them:
serverMetrics()instats/serverMetrics.tsbuilds the eight server metrics from the config andSessionManager.getOnlineSessions(), andServer.buildKernel()passes them tostatsModuleas itsmetricsoption.ServerMetricin the same file holds the eight names. The build first spread the metrics over their owners (buildTypeMetricinversion.ts,configMetricsinconfig/configMetrics.ts,SessionManager.metrics(), and amemorymetric the module registered); the review moved them into one file and madememorya chart built from the platform.TransportConnectiongained atransportfield (RakNetorNetherNet, fromTransportNames), since no connection said which transport carried it.player_platformkeys are display names fromDEVICE_OS_NAMES, such asAndroidandWindows, withUnknownfor a player with no device or an unnamed OS. The build first usedBuildPlatformmember names such asWIN32.player_protocolnames a protocol by the first release that speaks it, such as1.26.60, since a client names only its protocol.
Builds in packages/prismarine/src/stats/:
- The metric kinds (
gauge,label,distribution,breakdown; the review addedset) and theStatsSnapshottype, with itsplatformobject. StatsRegistry: register a metric under a namespacedsnake_casename, and take a snapshot.- The
StatsProviderandStatsProviderContextinterfaces. packages/prismarine/src/modules/stats.tsandstatsToken: the module provides the registry, starts its providers instart()and stops them instop(). It is registered inServer.buildKernel()with an empty provider list. The review split it into two modules, as Design describes.- The eight server metrics from the chart table, registered by the code that owns each value.
Leaves out bStats, config and any network call.
Done when tests show that a snapshot reads each metric once, leaves out a metric that throws or returns nothing, rejects a duplicate or badly formed name, and carries the platform fields; that each server metric reports the right value for a server with known players and settings; and that the module starts and stops a stub provider once per kernel start.
Phase 2: the bStats codec
Builds in packages/prismarine/src/stats/bstats/, as pure functions with no I/O:
service.ts: the service name, the service ID andmetricsVersion.- The chart table: metric name to chart type, for the eight charts. The review gave each chart a
buildfunction in its place. - The mapper from a chart name to its camelCase chart ID, which rejects the six default chart IDs,
locationMapincluded. - The chart encoders, with the left-out rules from the chart table under bStats wire protocol.
- The payload builder: a
StatsSnapshotand a server UUID in, the bStats JSON object out. - The request builder: URL, headers and the gzip body.
Leaves out scheduling, fetch and config.
Done when tests show each chart type's shape and its left-out rule, the chart ID for every mapped metric, the rejection of a default chart ID, the exact payload for a fixed snapshot, the filter strings in Charts to create on bstats.org, and a request body that gunzips back to the payload.
Phase 3: config
Builds in packages/prismarine/src/config/:
server-uuidat the top level: generated on first start, read back unchanged after.- The
stats.bstatssection withenabled,log-errors,log-sent-dataandlog-response-status-text, and the description comment above it. - Getters on
Configfor the UUID and the bStats settings, and a way to tell that this start created the section. - The
ConfigFiletype, key order, comments and the JSON schema, and whateverfirstBoot.test.tsandJsonSchemas.test.tsneed. pnpm run docs:facts, since the config tables are generated.
Leaves out the provider, the notice and JSP_BSTATS.
Done when tests show that a first start writes the UUID and the section with its comment, a second start reads the same UUID, a hand-edited enabled: false is kept, and a malformed UUID is replaced.
Phase 4: the bStats provider
As built, a submit that found enabled off ended the schedule, as MetricsBase.java does. The review removed that check: the provider reads its settings once per start, and /reload restarts it.
Builds BStatsProvider in packages/prismarine/src/stats/bstats/:
- The schedule from bStats wire protocol, on the injected timer and random source.
- Submit: snapshot, payload, request, injected
fetchwith a 10 second timeout. enabledchecked before scheduling. The build also checked it at every submit, until the review.- The three logging flags, and a failed submit that never throws into the server.
stop()clears the timers and aborts a request in flight.
Leaves out registering the provider on the server.
Done when tests with a fake clock, fixed random values and a stub fetch show submits at the first delay, the second delay and every 30 minutes after; both delay ranges at their extremes; no call when disabled; one log line per flag; no pending timer after stop(); and one schedule after a kernel restart.
Phase 5: wiring
serverBStatsProvider in stats/bstats/serverBStats.ts builds the BStatsProvider with the kernel, and the provider reads the config at each start, after it has loaded, since the kernel is built before it.
Builds:
Server.buildKernel()registers the stats module with the bStats provider, fed by the config from phase 3.- The provider stays off under Vitest, when
JSP_BSTATS=0is set and when the config file cannot be written. The review addedCIand the otherJSP_BSTATSvalues. - The first-run notice.
Done when tests show zero fetch calls for each of the three off cases, the notice once on a first start and not on a second, and a server that starts and stops cleanly with the provider on and a stub fetch. Run packages/prismarine and packages/server tests in full once, then start a flat-world server with log-sent-data on and check the logged payload by eye, without waiting on the timer.
Phase 6: docs and release notes
Builds:
- A page under
docs/guide/on what the server sends, to whom, and how to opt out, following thehuman-docsskill. - The chart list on that page as a docs fact generated from the chart table in
tools/docs/facts.mts. JSP_BSTATSwherever the other environment variables are documented.- A Changeset for
@jsprismarine/prismarine, after readingdocs/guide/versioning.md.
Done when pnpm run docs:facts leaves the tree clean and pnpm run lint passes.
Phase 7: maintainer review
Maintainer review, 2026-11-17 lists what came of it.
Not delegated. Send the branch to the bStats maintainer, as he asked, before it merges.
The OS question this phase first listed is answered. bStats' data processor (src/parser/os.rs in Bastian/bstats-data-processor) fills the os chart from osName and osVersion with Java's names in mind: a name that starts with Linux goes under Linux with the version, Windows Server, Windows NT and Windows go under their own slices with the name alone, Mac OS X goes under Mac OS X with the version, a name containing BSD goes under BSD, and anything else under Other. That is why bstatsOs() sends Mac OS X and a Windows edition instead of node:os's Darwin and Windows_NT, which would have landed under Other. The same processor reads metricsVersion as an optional string and does not check it.
Bring him three things:
- Whether
0.1.0is right formetricsVersion. - Confirm where the
locationchart comes from. The processor finds a country for the request's address with a GeoIP lookup, and a default chart whose template holds the predefined value%country.name%reports that country. Ask him to confirm that theserver-implementationtemplates givelocationthis value, so the chart fills with no field from us. - Tell him the first live submit is still untested: no test or manual run has sent a payload to bstats.org.
Review, 2026-11-12
A review after phase 6 reworked the code before the maintainer sees it. It changed:
- Metrics are raw values. The registry holds what the server knows, and bStats composes its charts through a
buildfunction per chart.build_typereads two labels, andmemoryreads the platform instead of a metric of its own. - A
setkind for the enabled transports, which the build sent as a distribution of ones. - Metric
descriptionandunit, carried into each reading. register()returns a disposer, andread(name)reads one metric.- One home for the server's metrics.
serverMetrics.tsreplacesbuildTypeMetric,configMetrics.ts,SessionManager.metrics()andServerMetric.ts.SessionManagerexposesgetOnlineSessions()instead. - A slim
StatsProviderContext: registry, logger and timer.fetchand the random source moved to the bStats provider's options, andnowwent. - Two kernel modules, so modules can register metrics before the providers start. Providers stop in reverse order, and a stop during a pending start stops that provider.
statsProviders, theServeroption for an embedder's providers, and the stats types in the package's exports.- Raw
StatsPlatformfields (type,release,version), with the bStats OS mapping inos.ts. - The config fails closed: once the section exists, only a literal
enabled: truereports. - More off switches:
JSP_BSTATStakes four off values and four on values, and warns on any other, and a setCIturns bStats off. buildType()reads the version for the npm package, which carries no stamp, instead of calling itdev.- Player platforms as display names, and
locationMapamong the reserved default chart IDs. - Settings read once per start, instead of
enabledchecked again at every submit. - A
429is not a failure, because bStats answers it for a second submit in the same window.
Left as it is, on purpose:
- The first-run notice stays tied to the start that writes the section. A start that writes it without reporting, such as one with
CIset, logs no notice, and later starts do not either. Remembering that the notice is still owed would take a persisted marker, which would be a visible config key for no operator benefit. - A module registered on the kernel after construction starts after the providers. The providers module is registered last in
Server.buildKernel(), so a module an embedder adds later starts after it, and a metric that module registers instart()misses the providers' first reading. bStats' first submit comes at least 3 minutes after the start, so it still sees such a metric.
Maintainer review, 2026-11-17
Bastian Oppermann, who runs bStats, reviewed the pull request. It changed:
- Raw OS fields. The payload sends
nodeOsType,nodeOsReleaseandnodeOsVersionin place ofosNameandosVersion, andos.tswent. bStats' data processor maps them (Bastian/bstats-data-processor#4), so a change in either format is fixed once on bStats' side. - A 60 second timeout, up from 10, so bStats can widen its proxy's retry window without clients giving up first.
- Pseudonymous, not anonymous. The UUID links one server's reports, so the config comment, the notice and the docs say pseudonymous. The config comment takes the text the review suggested for bStats' own clients.
- The UUID moved out of
config.jsonintoserver-uuid.txt, so a config copied between servers or mounted read-only does not share or lose it. - The timeout error's reference says it is logged only when
log-errorsis on, as the rejected-submit error's does.
Decisions
Settled on 2026-11-12, with the UUID's place changed on 2026-11-17:
metricsVersionis0.1.0.- Config is nested:
stats.bstats.enabled. - The UUID is a general server UUID, generated by the server, and bStats reads it. Since the maintainer review it lives in
server-uuid.txtrather than inconfig.json. - Per-player data such as device OS is published. Reporting is opt-out for the operator.
- Platform is one object with OS, architecture, version, core count and memory in GB.
- Charts are the eight in the chart table.
runtime_version,player_input,install_method,custom_contentandworld_presetwere proposed and dropped. - Packaging: bStats lives in
stats, insideprismarine. - Name:
statsfor the section, the folder and the token. - Default: every server reports, embedded ones included, with a first-run log notice and a description comment inside the config.
- Environment switch:
JSP_BSTATS=0disables bStats. The stats system gets no switch of its own for now. The review widened the values it takes, as Config lists. - Service:
JSPrismarine, ID 35257, kept as constants in one file. - Charts on bstats.org: the eight custom charts are created.
- Naming: metric names are
snake_casein the registry and camelCase on bStats, through a mapper.
Open questions
None for the build.