Operate
PeerDB Monitoring
Read-only PeerDB Mirrors and Peers section — configure PEERDB_API_URL to surface replication status, throughput, and lag without mutating PeerDB.
CHM includes an optional, view-only PeerDB section (Mirrors and Peers) that surfaces replication status, throughput, lag, and per-mirror detail from a PeerDB deployment. CHM never mutates PeerDB — it proxies a read-only allowlist of the PeerDB REST API.
Further reading: see the blog post for why CDC pipelines need this kind of monitoring — lag, replication-slot growth, and batch failures — and a walkthrough of the views below.
Open it at /peerdb once configured. The section is hidden until
PEERDB_API_URL is set.
What you can see
| View | Where | Highlights |
|---|---|---|
| Mirrors fleet | /peerdb | Status KPIs (count-up while still aggregating, last-known numbers cached), per-mirror throughput, prefix groups (qrep_sg_fleetreporting1_*) you can collapse, a lag-triage strip (worst-lag mirrors), and a collapsible logs & alerts feed aggregated across every mirror with error/warn/info filters. |
| Snapshot / QRep progress | mirror detail | Per-table initial-load progress from initial_load — partitions completed, rows synced, avg time per partition, and fetch/consolidate phase badges. QRep jobs add searchable, paged partition progress (UUID, duration, start/end, rows in partition vs synced) and a partition-sync history chart. |
| CDC batch history | mirror detail | Recent CDC batches (id, LSN range, rows, duration) plus a rows-per-batch chart. |
| Operation mix | mirror detail | Per-table insert / update / delete split from table_total_counts. |
| Slot health | /peerdb/peers | Replication slots across Postgres peers classified ok / warn / critical by lag, active state, and WAL status; worst-first. |
| Peer info | peer detail | Redacted peer config and server version from peers/info, alongside slots, slot-lag history, and active queries. |
Configure
Set the API URL and password
Set PEERDB_API_URL (and PEERDB_PASSWORD if your PeerDB API requires auth),
then restart the app.
For the PeerDB UI behind NextAuth, include the /api suffix:
PEERDB_API_URL=https://peerdb.example.com/api
PEERDB_PASSWORD=your-peerdb-ui-passwordFor a raw flow-api with no auth, use the bare origin:
PEERDB_API_URL=http://localhost:8113Tune caching and timeouts
| Variable | Default | Description |
|---|---|---|
PEERDB_API_URL | — | Base URL of the PeerDB REST API. For the PeerDB UI (NextAuth) include the /api suffix; for a raw flow-api use the bare origin (e.g. http://host:8113). |
PEERDB_PASSWORD | — | Sent as HTTP Basic with an empty username (base64(":" + password)). Leave empty if the API has no auth. Server-side only — never sent to the browser. |
PEERDB_CACHE_TTL_MS | 10000 | TTL for the server-side response cache (set 0 to disable). |
PEERDB_CACHE_MAX_ENTRIES | 500 | Max cached responses before oldest entries are evicted. |
PEERDB_FETCH_TIMEOUT_MS | 10000 | Upstream request timeout. |
PEERDB_HEALTH_TIMEOUT_MS | PEERDB_FETCH_TIMEOUT_MS | Timeout for the alert sweep's health probe (GET /v1/mirrors/list) only, so the one call that pages can have a longer deadline than every UI and agent read. The probe is retried once inside the same sweep before a failure counts. |
PEERDB_SWEEP_CONCURRENCY | 8 | Max in-flight reads per alert-sweep tick. Lower it if PeerDB struggles under the sweep. |
PEERDB_SWEEP_BUDGET_MS | 60000 | Wall-clock budget for one alert-sweep collection. Mirrors left unread when it elapses are deferred to the next tick. |
PEERDB_SWEEP_MAX_MIRRORS | unset (no limit) | Optional cap on mirrors read per alert-sweep tick. Leave unset so every listed mirror is read; see Partial coverage. |
See the full list in Environment Variables.
AI agent tools
The AI agent's read-only PeerDB tools (get_peerdb_mirror_status,
get_peerdb_metrics) follow CHM_FEATURE_PEERDB_AGENT:
CHM_FEATURE_PEERDB_AGENT | Agent tools |
|---|---|
| unset | On when PEERDB_API_URL is set and PeerDB answers a quick probe (CHM_AGENT_INTEGRATION_PROBE_TIMEOUT_MS, default 1500 ms). Off when it is unreachable or slow. |
true | On whenever PEERDB_API_URL is set. Errors show when a tool runs. |
false | Off. |
CHM_FEATURE_PEERDB_ENABLED=falseturns them off as well.- Anonymous cloud visitors never get them. Signed-in cloud users, and requests
bound to a user's own connection, need an explicit
true, because the PeerDB deployment is the operator's. - The decision is made once per conversation and kept for its later turns, so the tools never disappear mid-conversation.
- The tools are read-only and stay out of the always-loaded core set; the
agent finds them with
search_tools.
Connection status
The header shows a status pill that distinguishes:
- Connected — API reachable and authenticated.
- Auth failed — credentials rejected (check
PEERDB_PASSWORD). For the PeerDB UI this is the UI login password. - Unreachable — wrong
PEERDB_API_URLor a network/DNS issue. - Not configured —
PEERDB_API_URLis unset.
Security
Read-only proxy
CHM proxies only a read-only allowlist of PeerDB endpoints
(app/api/v1/peerdb/[...slug]). Mutating endpoints (create/drop/pause, alert
config, maintenance) are rejected with 403. The PeerDB credential is attached
server-side and never reaches the browser bundle, and secret-shaped peer config
fields are masked in the UI.
The section also respects
Feature Permissions — gate it with
CHM_FEATURE_PEERDB_ACCESS=authenticated or disable it with
CHM_FEATURE_PEERDB_ENABLED=false. The proxy enforces the same gate, so it
cannot be reached directly when the feature is disabled or restricted.
Local development (mock)
To preview the full UI without a real PeerDB instance, run the bundled mock server:
bun scripts/peerdb-mock-server.ts # serves :8113
PEERDB_API_URL=http://localhost:8113 pnpm run dev # → /peerdbLarge mirror fleets
PeerDB's only index on flow_errors is flow_name, so the mirror-logs
endpoint filtered by level=ERROR scans every error row for that mirror. On a
fleet with a multi-million-row flow_errors (QRep writes most of it at info)
that read is expensive and frequently returns nothing useful.
To make it cheap, add a composite index to the PeerDB catalog Postgres:
CREATE INDEX CONCURRENTLY flow_errors_flow_name_error_type_idx
ON flow_errors (flow_name, error_type);Without it, per-mirror ERROR-log reads degrade from a few hundred milliseconds to seconds, and enough of them in parallel will time out.
The alert sweep bounds its own load regardless of the index:
- it reads ERROR logs only for mirrors whose status is not
STATUS_RUNNING, or that report anerrorMessage— a healthy running mirror costs no log read; - it runs at most
PEERDB_SWEEP_CONCURRENCYreads at a time; - it stops starting new work after
PEERDB_SWEEP_BUDGET_MS, deferring the remaining mirrors to the next tick rather than overrunning the sweep.
On a 72-mirror fleet this turns ~100 log reads per tick into zero when the fleet is healthy.
Partial coverage
The alert sweep reads every mirror PeerDB lists. There is no hidden ceiling on fleet size: concurrency and wall-clock budget limit how fast it reads, not which mirrors it is allowed to read, and the mirrors most likely to alert are the ones it reads first.
A tick that could not read the whole fleet — because PEERDB_SWEEP_BUDGET_MS
elapsed, or because PEERDB_SWEEP_MAX_MIRRORS is set — says so rather than
reporting a clean result over a fleet it never looked at:
- the sweep summary reports the mirrors checked out of the mirrors listed, and flags the run as partial;
- an
alert_eventsaudit row with decisionpeerdb-coverage:partialrecords the counts, e.g.50 of 72 mirrors checked — partial result: 22 unchecked.
A partial run is a coverage fact, not an incident: nothing is dispatched for it
and no mirror's alert state is changed. The mirrors that were read are still
classified normally. Mirrors left unread are retried on the next tick, so a
fleet too large for one tick needs either a larger PEERDB_SWEEP_BUDGET_MS or
a smaller fleet — not a cap.
Logs
Show fleet logs & alerts on /peerdb opens one feed for every mirror. The
server reads POST /v1/mirrors/logs for each mirror PeerDB lists, through the
same bounded pool as the alert sweep (PEERDB_SWEEP_CONCURRENCY), so a large
fleet does not flood the PeerDB catalog and no mirror is left out by a fixed
cap. The browser makes one request: GET /api/v1/peerdb/log-patterns.
| Control | Options | What it does |
|---|---|---|
| Window | 1h · 24h (default) · 7d | Keeps only lines whose timestamp falls inside the window. Lines with no timestamp are dropped. |
| View | Patterns (default) · Raw | Patterns folds repeated lines into one row with a count, a sparkline, last seen, and the mirrors that hit it. Expand a row to see its raw lines. Raw lists every line, newest first. |
| Group by | Pattern · Mirror · Prefix · Table | Pattern groups lines whose text matches once numbers, ids, LSNs, and timestamps are masked. Mirror gives one row per mirror. Prefix groups mirrors by the same prefix groups /peerdb shows (for example qrep_sg_fleetreporting1_*); a mirror in no group keeps its own row. Table groups by the table a message names (... table public.orders), with (no table) for the rest. |
| Sort | Level · Last seen · Count | Level puts errors and warnings first. The other two sort by recency or by volume. |
| Level | All · ERROR · WARN · INFO | Filters lines before grouping. When errors or warnings exist, info patterns are collapsed behind a "Show N info patterns" button. |
Muting a pattern
In the Pattern group-by, each row has a Mute... control: 1 hour, 24 hours, or until unmuted. A muted pattern is hidden from the list, and a Show N muted button at the bottom reveals it with an Unmute action. Expired mutes disappear on their own.
Muting is per browser: it is stored in that browser's local storage, is not shared with other people or devices, and is lost if site data is cleared. It only hides a pattern from this feed and does not affect alerts. To silence alerting on a pattern, use the PeerDB alert rules.
The header shows how many mirrors were read out of how many PeerDB lists. A note appears under it when coverage is incomplete:
- some mirrors failed or did not answer within the request budget (25s);
- some mirrors have more lines in the window than one read returns (100 per mirror). Open the mirror to see all of its logs.
Responses for the deployment's own PeerDB are cached in memory for 30 seconds
per window. Requests for a per-user connection (?connection=<id>) are never
cached.
Alerting
The scheduled health sweep also evaluates every PeerDB mirror and sends alerts through the same pipeline as ClickHouse alerts (dedup, cooldown, recovery notices, maintenance windows, quiet hours, ACKs, channel fan-out). It is read-only: it never pauses, resumes, or restarts a mirror.
What is checked
Each mirror is classified ok / warning / error from its read-only status:
| Signal | Warning | Error |
|---|---|---|
| Mirror status | STATUS_PAUSING, STATUS_PAUSED, STATUS_TERMINATING, STATUS_UNKNOWN | STATUS_FAILED, STATUS_TERMINATED |
Mirror errorMessage | — | present |
| CDC lag | at least 300 s | at least 1800 s |
| Replication slot lag | at least 512 MB | at least 2048 MB |
| Recent ERROR log entries | at least 1 | at least 5 |
| Snapshot (initial load) | not finished 24 hours after it started | — |
CDC throughput (rowsSynced) | unchanged for at least 1800 s | — (set one with a rule) |
When the error-log count could not be read, the alert says "error count
unavailable" instead of reporting zero errors. Mirrors that are
STATUS_RUNNING with no errorMessage skip the log read (see
Large mirror fleets).
The thresholds above are the defaults. A stale running mirror (no CDC lag reported, last sync batch too old) is a warning after 1800 s and an error after 7200 s.
Throughput zero. rowsSynced is a running total, so the sweep keeps the
previous total for each mirror between runs, in a small
peerdb_throughput_samples table on the same database the PeerDB rules use.
Without that database the check is off. A STATUS_RUNNING CDC mirror whose
total has not grown for 1800 s is a warning (reason throughput-zero-warning,
or throughput-zero-error once a rule's critical threshold is reached). The
first sweep after a mirror appears only records a sample, so it never fires.
QRep mirrors and mirrors that are not running are not checked, and a paused
mirror starts a fresh window when it resumes. A quiet source table with no
changes also reads as zero throughput: raise the threshold or mute it with a
throughput-zero rule.
Configure thresholds and mutes
Add PeerDB mirror rules to change the thresholds for some mirrors, or to mute them for a while. Rules live in two places, and both apply:
- Settings → Alerts → PeerDB mirror rules. List, add, edit, enable, and
mute rules. Saving needs a database backend (cloud, or self-hosted with a D1
database or a Postgres
DATABASE_URL); without one the panel says so and stays read-only. alerts.yamlpeerdbRules, for a deploy with no database. See Run alerts without a metadata database.
peerdbRules:
- id: fleetreporting-lag
check: lag # lag | slot-lag | errors | stale-sync | throughput-zero
matchKind: glob # exact | prefix | glob (default)
match: qrep_sg_fleetreporting1_*
warning: 3600
critical: 14400
severity: critical # or warning: never escalate past warning
enabled: true
muteUntil: null # ISO-8601 time to mute the matching mirrors untilA rule replaces the warn/crit pair of one check for the mirrors it matches. The other checks keep the defaults. When several enabled rules for the same check match a mirror, the most specific one wins:
exact(the mirror name),- then
prefix(the longest prefix), - then
glob(the one with the most characters other than*and?).
If two rules are still tied, the one with the lower id wins. Matching is not
case-sensitive. Status checks (STATUS_FAILED and others) and the
errorMessage check are not changed by rules.
A muted mirror is still checked, shown in the sweep summary, and written
to alert history (peerdb-hold:muted), but no notification is sent, not even
a recovery. A recovery is sent on the first sweep after the mute ends. Disabled
rules are ignored, mute included. With no rules, every mirror uses the
defaults, and alert keys stay the same.
Requirements
PEERDB_API_URLis set (andPEERDB_PASSWORDif your API needs it).- The sweep runs on a schedule: call
GET /api/cron/health-sweepwithAuthorization: Bearer $CRON_SECRET(for example from Cloudflare Cron). See Health-sweep cron alerting. - At least one notification channel (webhook, email, Slack, and so on).
HEALTH_ALERT_ENABLEDis optional and defaults on once a channel is configured.
Routing
Each mirror alert uses the host name peerdb:<mirror>, so an alert route can
target PeerDB with a host glob: peerdb:* for all mirrors, or
peerdb:orders_* for a group. A route matches by host with * and ? globs,
case-insensitive. A mirror that matches no route falls back to the global
webhook.
Dry run
When no channel is configured, or HEALTH_ALERT_ENABLED is set to false, the PeerDB cycle still runs in dry
run: mirrors are evaluated and an alert_events audit row is written for each
one, but nothing is sent. Findings still appear in the sweep summary.
Turn it off
Set CHM_FEATURE_PEERDB_ENABLED=false to disable PeerDB entirely. This hides
the section, blocks the proxy, and skips the PeerDB alert cycle in the sweep.
The ClickHouse sweep is unaffected. See
Feature Permissions.
Troubleshooting
| Symptom | Likely cause |
|---|---|
| Every PeerDB check reports errored on a large fleet | The sweep is timing out against the PeerDB catalog. Add the flow_errors (flow_name, error_type) index above, and lower PEERDB_SWEEP_CONCURRENCY. |
| Pill shows Auth failed | Wrong PEERDB_PASSWORD. For the PeerDB UI, use the UI login password; for a raw flow-api, match its configured password (or leave empty). |
| Pill shows Unreachable | PEERDB_API_URL host/port wrong, or the API is not reachable from the CHM server. |
| Mirrors load but charts are empty | The mirror has no recent CDC graph/batch data yet, or the PeerDB version doesn't expose those endpoints. |
| Large fleets show partial KPI totals | Per-row metrics load lazily above 24 mirrors; the Throughput/Rows-synced cards label how many mirrors are loaded. Expand a row to load its metrics. |
Alert sweep reports peerdb-coverage:partial | The tick ran out of budget (or PEERDB_SWEEP_MAX_MIRRORS is set) before reading every mirror. Raise PEERDB_SWEEP_BUDGET_MS, lower PEERDB_SWEEP_CONCURRENCY if reads are timing out, or unset PEERDB_SWEEP_MAX_MIRRORS. See Partial coverage. |
Related
Feature Permissions
Gate or disable the PeerDB section with CHM_FEATURE_PEERDB_ACCESS and CHM_FEATURE_PEERDB_ENABLED.
Environment Variables
Full reference for all PeerDB and connection variables.
Blog: Monitoring PeerDB: snapshot progress, batch history, fleet lag, and slot health