Metrics, exporters and health checks
§M14.18
Ez az oldal a nucleus saját dokumentációjából készül, ezért angol nyelvű.
One registry, many ways out. nucleus_platform::metrics holds the
process’s instruments: counters, gauges and histograms (fixed
logarithmic buckets — powers of 4 µs, 1 µs to 16.8 s, then +Inf), each
a static in the layer that records into it, kept in atomics, so
recording is a relaxed atomic add (no lock, no allocation), and a
CounterFamily for a label whose values come at run time (a front
end’s name). What a layer already counts is not counted twice: a
collector reads it when a snapshot is taken (the page cache’s
counters, the pages in use, the open sessions). Registry::snapshot
reads everything; two databases open in one process add up (a server
has one). An Exporter — a module — is given the registry: a pull
one serves snapshots when asked, a push one sends them on its own
schedule.
| metric | kind | what |
|---|---|---|
nucleus_statements_total{kind} |
counter | statements run: read (queries) or write |
nucleus_statement_errors_total |
counter | statements that failed |
nucleus_statement_duration_seconds{kind} |
histogram | their time (waits for a budget left out) |
nucleus_rows_read_total, nucleus_rows_returned_total |
counter | rows read; returned or changed |
nucleus_commits_total, nucleus_rollbacks_total |
counter | transactions committed; ended otherwise (rolled back, dropped, a failed commit) |
nucleus_conflicts_total |
counter | serialization conflicts (40001) |
nucleus_transactions_running |
gauge | transactions running |
nucleus_oldest_transaction_seconds |
gauge | how long the oldest running transaction has run |
nucleus_wal_bytes_total, nucleus_wal_syncs_total |
counter | bytes appended to the WAL; syncs that made it durable (a group commit is one) |
nucleus_wal_since_checkpoint_bytes |
gauge | the main branch’s WAL since its last checkpoint |
nucleus_checkpoints_total |
counter | checkpoints finished |
nucleus_cache_{hits,misses,evictions,writebacks}_total |
counter | the page cache’s |
nucleus_cache_pages, nucleus_cache_pages_used |
gauge | frames it has; frames holding a page |
nucleus_data_file_bytes, nucleus_data_file_free_bytes |
gauge | the data file (every branch’s pages); its free pages |
nucleus_branches |
gauge | branches, main included |
nucleus_sessions{front_end} |
gauge | sessions open |
nucleus_sessions_opened_total{front_end} |
counter | logins admitted |
nucleus_logins_refused_total{front_end}, nucleus_logins_locked_total |
counter | logins refused; refused because the role was locked |
nucleus_model_{calls,errors,tokens,cached}_total |
counter | embedding models’ calls (§8.23) |
nucleus_build_info{version}, nucleus_ready |
gauge | always 1; 1 once the server is ready |
nc_catalog.metrics (name, kind, labels, value, help)
reads the same snapshot — a histogram as Prometheus has it, _bucket
by le, _sum, _count; labels as kind="read" — so a client, the
console and an AI model see what Prometheus sees. nucleus status
reads it over a connection and sums it up for people: ready or not,
sessions, transactions, statements with p50 and p99 (estimated from the
buckets as histogram_quantile does), the page cache’s hit ratio, the
files’ sizes, refused logins.
Prometheus (modules/prometheus): nucleus server --metrics [addr] (default 127.0.0.1:20037) serves GET /metrics in the text
exposition format 0.0.4, or OpenMetrics 1.0 when the scraper’s Accept
asks; GET /health/live (200 while the process answers) and GET /health/ready (200 once recovery is done, the store open and the
listeners up; 503 before); and, for a load balancer sending writes
to the primary and reads to replicas (§9 “Managing a cluster”), GET /health/primary and GET /health/replica[?lag=<commits>][&lag_seconds= <s>]. Its listener starts before the database
opens, so an orchestrator sees a long recovery as alive and not ready.
Over TLS when the server has a certificate; beyond loopback over plain
HTTP only with --insecure.
OpenTelemetry (modules/otlp): --otlp <endpoint> or the SDKs’
OTEL_EXPORTER_OTLP_ENDPOINT (with OTEL_EXPORTER_OTLP_HEADERS,
OTEL_METRIC_EXPORT_INTERVAL in ms, 60 s by default) pushes a snapshot
to <endpoint>/v1/metrics every interval, OTLP/HTTP in JSON:
cumulative temporality from the process’s start, a counter a monotonic
sum, a histogram with explicit bounds (each bucket’s own count), the
resource service.name = nucleus. A failure is logged once and again
when sending works; TLS to anything but loopback.
Traces (§M14.18 O2b): with --otlp, a span per statement goes to
<endpoint>/v1/traces (batched every 5 s, at most 2048 waiting — more
are dropped and the drop logged): server kind, named by the statement’s
first word (SELECT, INSERT), with the database semantic conventions’
attributes — db.system.name (nucleus), db.namespace (the branch),
db.operation.name, db.query.text (normalized: constants are $n, as
in nc_catalog.statements, so no value leaves in a trace), db.user,
db.response.returned_rows, nucleus.rows_read, nucleus.front_end,
and on failure the error status with db.response.status_code (the
SQLSTATE). A client puts its statements in its own trace with a W3C
traceparent — SET traceparent = '00-<trace>-<span>-01' (until
RESET), or per statement a sqlcommenter comment, SELECT … /*traceparent='00-…-01'*/ — and its sampled flag decides; a statement
outside one starts a trace, kept by OTEL_TRACES_SAMPLER
(parentbased_traceidratio with OTEL_TRACES_SAMPLER_ARG=0.1 keeps a
tenth; always_off or OTEL_TRACES_EXPORTER=none: no spans). Spans
are made only while the exporter is installed (nucleus_platform::trace:
one relaxed load per statement otherwise).
Recording costs nothing measurable: the kv benchmark and bench/run.py
against the commit before, within the runs’ spread
(docs/benchmarks.md, Metrics).