Skip to content

Monitoring and Alerts

Mohammad Rasoul Kazemi edited this page Dec 1, 2026 · 5 revisions

Monitoring and Alerts

What kingresd watches, the alerts it raises, the metrics it exposes and the logs it keeps. All of it is built and matches kingres/control-plane/internal/monitor and the contract (AlertKind has 45 kinds; the ones that nothing raises are listed below). No metrics store is bundled (ADR 0020); for history, scrape /metrics with your own Prometheus. See Operations for the rest of the operator's pages.

How alerts work

  • A monitor round runs on every server every monitor-interval (default 10s, env KINGRES_MONITOR_INTERVAL). It raises and clears alerts in the system database (kingres_cp.alert) for its own server. The manager leader raises the alerts about other servers and about the cluster.
  • There is one open alert per kind and subject. A condition that holds again updates the open alert (severity and message) and never raises a second one. A kind whose reading was not measured is neither raised nor cleared. An open alert survives a restart of kingresd.
  • A condition that ends clears the alert (state resolved). A person can acknowledge an open alert (acknowledgeAlert, role kingres_ops); that changes its state to acknowledged and does not clear it. Listing alerts needs kingres_readonly.
  • Where to see them: the REST operations GET /api/v1/alerts (filter by state and severity) and POST /api/v1/alerts/{alertId}/acknowledgement (REST API Reference), and the console (Web Console). Since contract 0.5.0 the listing is cluster-wide: a server collects the alerts of the others, and an alert id carries the number of the server that holds it. Severities are info, warning and critical.
  • Each alert has a typed subject (server, group, database, task, aspect) that a client reads instead of parsing text.

Alerts of the periodic checks

Kind Raised when Severity Cleared when
serverDown The instance of this server is not running (own check). The manager leader also raises it for another server whose heartbeats stopped for failure-timeout (default 10s) critical The instance runs again, or the server is heard again. An outage that ended is also recorded as a resolved alert
serverSuspect A server sent no heartbeat for suspect-timeout (default 5s) but is not yet dead warning The server is heard again
diskSpaceLow The data disk is at least 90% full (warning) or 95% (critical) warning, critical Below 90%
memoryPressure Less than 10% of the memory of the server is available warning Back above 10%
replicationLagHigh A standby of the server is more than 60 seconds behind, or the replication slot of a standby of a group holds more WAL than the warning limit (then the slot is dropped at the retention limit and the standby is rebuilt) warning The lag is below the limit
certificateExpiring The server's own certificate has less than half of the part of its lifetime at which it is renewed left: warning; less than an eighth, or expired: critical. For the cluster certificate authority (subject aspect ca): less than a year left is a warning, less than 30 days is critical. The CA is not rotated warning, critical The certificate was renewed
certificateRenewalFailed Three renewals in a row failed on that server warning; critical when less than a tenth of the lifetime is left A renewal succeeds, or the certificate was renewed by other means
ledgerPendingTooOld The oldest pending ledger transaction of a database has waited ledger-pending-max-age (default 5m, env KINGRES_LEDGER_PENDING_MAX_AGE). The age is what the monitor observed: a restart of kingresd forgets it, and a new oldest entry starts it again, so it can only under-estimate warning; critical at twelve times the limit The queue of the database is empty or its oldest entry changed
versionMismatch The servers that answer report different versions of KingresDB, of PostgreSQL or of an extension (kingres_shard, kingres_ledger). The manager leader checks every version-check-interval (default 1m). Needs at least two answers warning The servers agree
replicationPending The manager leader keeps a change of roles, grants or settings waiting for a server it could not reach. Until the change arrives a role that was disabled, changed or dropped may still work on that server warning after 1 minute, critical after 10 The server has applied the change
leaseLost The kingresd that runs the primary of a group could not renew the group's lease in time. With a standby, the primary was stopped (fenced). Without one, it keeps running and writes are not protected by a lease critical The lease is held again
groupWithoutSynchronousStandby A group's standbys have not streamed for longer than the grace period (standby-sync-grace, default 30s) and the primary no longer waits for them: commits exist on one server only critical A synchronous standby streams again
groupUnderReplicated Fewer standbys stream than the replica count, for three checks in a row. A cluster of one server never raises it warning The count is reached
clockDifference The clock of a server differs from the manager leader's by more than clock.maxDifferenceMs (default 1000 ms, a cluster setting), less the uncertainty of the measurement. kingresd does not set the clock: run NTP or chrony warning; critical at ten times the limit Back within the limit. An unreachable server is left to serverDown

Alerts of failover and standbys

Raised by the failover task and the standby code. See High Availability. Failover is new in the first release: test your recovery procedure on your own cluster before you rely on it.

Kind Meaning
failoverNeedsDecision critical. A failover could lose data and waits for allowDataLoss
failoverBlocked warning or critical. A failover cannot proceed: no standby to promote, the deciding server cannot hear a majority, the old lease holder is still heard, or the catalogs cannot be followed
failoverDataLoss warning. check_cluster() reported lost or rolled back transactions after a failover
splitPromotion critical. Two instances of a group are out of recovery, or an instance was promoted outside the failover
oldPrimaryNotStopped critical. The old primary could not be stopped; the lease keeps it from acting
oldPrimaryRunning critical. The old primary runs after the catalog moved; it is being stopped
oldPrimaryNotRebuilt warning. After the shorter of ten minutes and half of standby-replace-after (default 30m) the old primary is still not a standby
autoFailoverTriggered info. An automatic failover ended
autoFailoverLimitReached critical. The limit autoFailover.maxCount is reached; fail over by hand or reset the counter
certificateAuthorityUnavailable critical, subject cluster. After a failover of the map group the new leader holds no key of the certificate authority (the escrow was off or its copy was not current); no certificate can be issued, renewed or revoked until pki/ca.key and pki/revoked.json of the old leader are restored from its backup
taskFailed warning. A rebalance ended failed (subject task:<id>); a cancelled rebalance raises none
rebalanceFailed warning, subject cluster. The last automatic rebalance failed; the automatic mode is suspended until an operator starts a rebalance or looks at the report

Alerts of tables, transfer and extensions

Kind Meaning
partitionsAheadLow warning. The last partition of a table with a time-partition policy ends before the lookahead floor (subject: the table)
partitionPolicyFailed warning. The last run of a time-partition policy did not succeed, or the policy is not run (subject: the table)
transferStagingLow warning when the staged files of the data transfer hold 90 percent of dataTransfer.stagingQuotaBytes, critical at 98 percent. Raised by the server that holds the files, the manager leader
extensionSchemaUntrusted critical. The schema of a KingresDB extension in a database is not owned by a superuser, holds an object that is not a member of the extension, or lets a role that is not a superuser create objects in it; the readings of that database that depend on the extension are not available until the owner and privileges are restored
extensionSkipped warning, one alert for each skipped extension (subject: server and database, aspect extension:<name>). An extension of a database was not installed on a server because a role of the tenant made the schema of the extension its own. Adding the server again re-applies it; see operator guide, section 10

Alerts of the ledger

The alert kinds were added to the contract in 0.11.0; the subjects are in the AlertSubject schema. See Ledger Signing and Publication and Ledger Anchoring for these parts.

Kind Meaning
ledgerNotAnchored A database has ledger tables and no anchor target is enabled. info, warning when the setting anchor.required is on
ledgerAnchorBehind The anchoring of a target is behind. warning, critical
ledgerAnchorFailed An anchor record is failed or expired. critical
ledgerAnchorConflict The store holds a different object under the name of an anchor. critical
ledgerChainDiverged A chain no longer extends its published log. critical. Needs an operator (Runbooks)
ledgerGroupUnread The chain of a shard group could not be read. warning, critical
ledgerPublicationBehind In the contract (the newest signed checkpoint of a chain is older than five publication intervals while its head advanced; warning); in 0.2.0 nothing raises it. In release 0.2.1, the scheduled audit of the publication raises it (warning) when the head of the database has advanced and the newest checkpoint is older than five publication intervals, or a log has leaves and no checkpoint
ledgerPublicationAltered (since 0.2.1) The scheduled audit found that a tile, a stored checkpoint, a signature or a block of the database is not what it must be, or that the publication was emptied, shrunk or rolled back against the high-water mark. critical, and sticky: it stays until an administrator acknowledges it (acknowledgeLedgerPublicationAlteration, kingres-cli ledger audit-ack), whatever a later audit finds. See Ledger Anchoring
ledgerPublicationUnreadable (since 0.2.1) The store, the key set or a shard group could not be read, so the audit cannot say (an unreadable store is never reported as altered). warning, critical after three audits in a row
ledgerSignerUnavailable No checkpoint could be signed for two rounds, the key set is damaged, the key file is missing on the leader, or (subject published-state) the database is behind the record of what was published. critical
ledgerDigestOverdue No digest within twice digestIntervalSeconds. warning

Kinds in the contract that nothing raises

The enumeration AlertKind in the contract also lists underReplicatedBuckets, unavailableBuckets, rebalanceNeeded, mapGroupUnavailable, ledgerVerificationFailed and ledgerPublicationBehind. The control plane code contains no place that raises them. Clients must tolerate kinds they do not know.

Metrics

  • Sampler. Every 10 seconds kingresd fills a bounded in-memory ring (1440 points per series, 2000 series). Series: connections, cpuUsagePercent, memoryUsedBytes, diskUsedBytes, replicationLagSeconds, replicationLagBytes per server; databaseSizeBytes and transactionsPerSecond per database; and, for the data transfer, transferStagingUsedBytes, transferStagingFreeBytes, transfersRunning and transfersStaged. The ring is lost at a restart.
  • GET /api/v1/metrics/query resamples the ring (average per step, at most 5000 points per series, 422 beyond). queriesPerSecond and bucketsUnderReplicated are in the contract and have no samples yet. The console charts read this operation.
  • GET /metrics is Prometheus text, one gauge per series named kingres_<name in snake case> (for example kingres_disk_used_bytes, with labels server and database). It is outside the REST contract and requires authentication: a bearer token of a session with the role kingres_stats or better, or the scrape token metrics-token (env KINGRES_METRICS_TOKEN); without either it answers 401.
  • Client entry point counters. When the client entry point is on, /metrics also carries kingres_client_connections_accepted, _active, _refused, kingres_client_connect_failures, kingres_client_connections_moved, kingres_client_connections_idle_closed, kingres_client_bytes_in, kingres_client_bytes_out and the same with kingres_client_standby_ for the standby entry point. They are listed in the contract's metric enumeration for /metrics/query as client... and clientStandby... series.
  • Cluster-wide: the metrics and alerts reads are gathered from every server within gather-timeout (default 3s); a server that does not answer is left out.
  • Health: GET /healthz and GET /readyz need no sign-in.

Logs

  • Manager log. kingresd logs through slog, to the journal when run by the unit: journalctl -u kingres. log-level (debug, info, warn, error; default info) and log-format (text or json) are settings; the level can be changed at run time from the console (updateThisServerSettings) and a saved level wins over the configured one until changed again. Values are quoted, and the audit sink cleans actor and text, so a request cannot forge a line.
  • Instance log. The PostgreSQL log of a package install is in /var/lib/kingres/instances/1/pgdata/log/ (weekday-rotated). The console and GET /api/v1/this-server/logs read the last part of it (from at most the last 1 MiB of at most 8 postgresql-*.log files); GET /api/v1/logs gathers the logs of all servers.
  • Event lines of the client entry point are logged at debug level and carry no address and no data.

Audit log

Every changing operation writes an event to audit.jsonl in the data directory of the server that handled it (setting audit-file); the file rotates at 64 MiB into audit.jsonl.<first id> and segments are never deleted. GET /api/v1/audit reads it. An event names the actor, the action (the contract lists many, for example login, loginFailed, setupTokenRejected, failoverServer, autoFailover, startRebalance, acknowledgeAlert, createLedgerSigningKey, revokeLedgerSigningKey, acknowledgeLedgerDivergence, certificateRenewalFailed, leaseLost), the outcome and the request id (X-Request-Id). Credentials are never in an entry. The signing and anchoring rounds write no entry per round; their failures are alerts and log lines. The audit file survives a reset of the server when it leaves a cluster. See Security Model.

What to watch first

This is a reading of the tables above, not a rule from the sources: serverDown, leaseLost, groupWithoutSynchronousStandby, splitPromotion, ledgerChainDiverged, ledgerSignerUnavailable and certificateAuthorityUnavailable are the critical kinds that say the cluster or its evidence is at risk; start with Runbooks.

Sources

Clone this wiki locally