Getting Started

Install the module, point it at a collector, and see exactly what it sends.

Requirements

BoxLang 1.19+. No other dependencies.

Install

bashinstall-bx-module bx-monitor          # into BoxLang HOME
install-bx-module bx-monitor --local  # into ./boxlang_modules
box install bx-monitor                # with CommandBox

Installed but not configured, the module logs one line (bx-monitor is disabled: no collectorUrl is set) and does nothing else.

What it reports

  • Registration on startup: server name, environment, tags, host name, BoxLang, Java and OS versions, installed modules.
  • A heartbeat every 30 seconds (the collector can change the pace): JVM memory, thread count and CPU, the result of each health check, request counts and timings per route, and errors since the last heartbeat, redacted.
  • A goodbye on graceful shutdown, so a dashboard can tell "stopped" from "lost".

The collector is a separate project. Anything that speaks the protocol will do.

Configuration

Settings go in boxlang.json under modules.bxMonitor.settings:

json"modules": {
	"bxMonitor": {
		"settings": {
			"collectorUrl": "${env.BX_MONITOR_URL}",
			"apiKey": "${env.BX_MONITOR_KEY}",
			"serverName": "feedhouse-prod",
			"environment": "production",
			"tags": [ "boxexpress", "docker" ],
			"datasources": [ "main" ],
			"diskPaths": [ "/" ]
		}
	}
}

Use ${env.NAME}, or ${env.NAME:default} with a non-empty default. BoxLang 1.19 leaves an unset ${env.NAME} and an empty default (${env.NAME:}) in place as literal text. A collectorUrl that still contains ${ is treated as not configured and the log says so, so a missing variable turns reporting off rather than breaking anything.

Settings

SettingDefault
enabledtruefalse makes the module inert.
collectorUrl""Your collector's base URL, such as https://monitor.example.com. A path prefix is kept. Empty, unresolved or not http(s) means inert. Plain http:// to anything but this machine logs a warning.
apiKey""Sent as Authorization: Bearer <apiKey>.
serverName""The name the collector shows. Empty means the host name.
environment"production"Free text.
tags[]Free text labels.
heartbeatIntervalSec30Used until the collector's register answer sets its own. 5 to 3600.
timeoutMs5000Connect and read timeout for each call to the collector. 250 to 120000.
datasources[]Datasources defined in boxlang.json to ping before each heartbeat.
datasourceCheckSql"SELECT 1"The ping.
diskPaths[]Paths whose free space is checked.
diskDegradedPct10Below this percentage free, the disk check is degraded.
diskDownPct3Below this percentage free, it's down.
checkTimeoutMs5000Each check's own time limit.
captureErrorstruefalse reports no errors at all.
errorDetail"redacted""full", "redacted" or "none". See Errors and Redaction.
redactKeyspassword, secret, token, apikey, cookie, session and othersNames whose values are never sent.
redactPatterns[]Extra regular expressions (Java syntax); every match becomes [redacted].
maxStackFrames40Stack traces are cut to this many lines.
maxBufferedErrors500Errors held between heartbeats. When full, the oldest is dropped and counted.
maxRoutesPerHeartbeat50The busiest routes are listed; the rest are summed as <other>.
agentIdFile""Where the agent id is kept. Empty means <BoxLang home>/bx-monitor/agent-id. See How It Works.

See exactly what is sent

examples/stub-collector.bxs in the repository is a stand-in collector that prints every request it receives:

bashboxlang examples/stub-collector.bxs 8089 5

Set collectorUrl to http://127.0.0.1:8089, start your server, and read the output. The second argument is the heartbeat interval the stub asks for, in seconds. Do this before pointing the module at anything real.