Health Checks
The checks that run before each heartbeat, and how to add your own.
Built in
datasource:<name>for each entry indatasources. RunsdatasourceCheckSql(SELECT 1).disk:<path>for each entry indiskPaths.degradedbelowdiskDegradedPct(10%) free,downbelowdiskDownPct(3%).
Your own
Register a check from anywhere in your app:
jsmonitorRegisterCheck( "queue", () => {
var waiting = queueDepth()
return { status: waiting < 100 ? "ok" : "degraded", detail: "#waiting# waiting" }
} )
The function returns { status: "ok" | "degraded" | "down", detail: "" }.
| What happens | Reported as |
|---|---|
| The check throws | down, with its message, redacted |
| It returns anything else | down |
It runs past checkTimeoutMs | down |
| It's still running from the previous heartbeat | not started again |
The heartbeat's overall status is the worst check. With no checks, it's ok.
monitorRegisterCheck() does nothing when the module is disabled and never throws, so the call can stay in place everywhere.
Datasources defined in Application.bx
Checks run on a background thread, outside your application, so a datasource that only your Application.bx defines can't be found by name, neither by datasources nor by a check of your own. It reports down with a detail saying so.
Hand the check the definition instead:
jsvar definition = getApplicationMetadata().datasources.main
monitorRegisterCheck( "datasource:main", () => {
queryExecute( "SELECT 1", [], { datasource: definition } )
return { status: "ok", detail: "" }
} )