Metrics and alerts
Superseded for scope. Alerts and dashboards now live in
docs/architecture/OBSERVABILITY-ALERTS-RUNBOOKS.md(whole app + delivery mechanism).
No threshold in this document is a measured production value. They are proposed
initial settings, labelled: [est] estimate, [measured-local] seen in local runs
(recorded in QUEUE-CONCURRENCY-AND-THROUGHPUT.md), [unproven] needs a staging
measurement before it can be trusted. Alerts must be re-tuned after staging.
1. Metric set (by subsystem)
API
| Metric | Type | Source | Why |
|---|---|---|---|
http_requests_total{route,method,status} | counter | log-derived counter / Analytics Engine | rate + error ratio |
http_request_duration_ms{route} | histogram (p50/p95/p99) | Analytics Engine | latency SLO |
auth_rejections_total{reason} | counter | log event | security + UX |
cap_refusals_total{kind} | counter | cap.reached | demand vs allowance |
Queues
| Metric | Type | Source | Why |
|---|---|---|---|
queue_depth{queue} | gauge | Queues analytics | backlog |
oldest_message_age_s{queue} | gauge | Queues analytics | primary saturation signal |
retries_total{queue} | counter | log event | systemic failure |
dlq_depth{queue} | gauge | Queues analytics | silent failures |
consumer_invocations{queue} | counter | Queues analytics | actual concurrency |
Scrapers
| Metric | Type | Source |
|---|---|---|
scrape_requests_total{service,source} | counter | backend log + scraper log |
scrape_duration_ms{service,source} | histogram | scrape.dispatch.completed |
scrape_outcome_total{service,source,outcome} | counter | dispatch events |
scrape_http_status_total{service,status} | counter | dispatch events |
scrape_empty_total{source} | counter | outcome=empty — an empty board is a fact, not an error |
scrape_uncertain_total{source} | counter | uncertain dispatch — must be zero in steady state |
scraper_quota_refusals_total{service} | counter | 402 responses |
gateway_exit_ready | gauge | gateway /health scrape by cron |
D1
| Metric | Type | Source |
|---|---|---|
d1_rows_written_total | counter | db.batch.committed |
d1_batch_duration_ms | histogram | same |
d1_batch_failures_total{err_code} | counter | db.batch.failed |
d1_slow_queries_total | counter | db.query.slow |
db_size_bytes | gauge | wrangler d1 info daily cron |
retention_rows_deleted{kind} | counter | retention.run |
AI / Gmail / R2
ai_calls_total{outcome}, ai_latency_ms, ai_tokens_total, ai_rate_limited_total,
gmail_token_refresh_total{outcome}, gmail_send_outcome_total{outcome},
r2_ops_total{op,outcome}, r2_orphans_total.
2. Alerts
| ID | Alert | Sev | Condition (proposed) | Window | Target | Runbook |
|---|---|---|---|---|---|---|
| AL-01 | Search stuck running | S1 | searches.status='running' older than lease (10 min) > 0 rows | 5 min | on-call | RB-03 |
| AL-02 | DLQ non-empty | S1 | dlq_depth > 0 | immediate | on-call | RB-05 |
| AL-03 | Queue backlog ageing | S1 | oldest_message_age_s > 900 | 5 min | on-call | RB-02 |
| AL-04 | API 5xx ratio | S1 | 5xx / total > 5 % | 5 min | on-call | RB-12 |
| AL-05 | Scrape uncertain | S1 | scrape_uncertain_total increase | immediate | on-call | RB-06 |
| AL-06 | All sources failing | S2 | scrape_outcome{outcome=failed} > 50 % | 15 min | on-call | RB-04 |
| AL-07 | Gateway degraded | S2 | gateway_exit_ready == 0 | 2 min | on-call | RB-07 |
| AL-08 | D1 batch failures | S2 | d1_batch_failures_total > 0 | 5 min | on-call | RB-11 |
| AL-09 | Scraper quota refusals | S2 | scraper_quota_refusals_total > 0 | 15 min | owner | RB-09 |
| AL-10 | Retention sweep absent | S2 | no retention.run for 2 expected intervals | 1 h | on-call | RB-17 |
| AL-11 | Logpush gap | S2 | partition completeness check fails | daily | on-call | RB-18 |
| AL-12 | Crown dependency missing | S2 | CONFIG_* 503 count > 0 | 5 min | on-call | RB-08 |
| AL-13 | Auth rejection spike | S3 | auth_rejections_total > 10× baseline | 15 min | security | RB-10 |
| AL-14 | Empty-board ratio anomaly | S3 | one source empty share > 80 % and failed == 0 | 1 h | owner | RB-07 |
| AL-15 | R2 orphans detected | S3 | r2_orphans_total > 0 | daily | owner | RB-13 |
Note on AL-14: an empty board and a broken parser both produce zero rows; only the pairing
with failed == 0 + history distinguishes them, and that requires per-source history that
does not exist yet (see FAILURE-MODE-REGISTER.md FM-12).
3. Dashboards (minimum)
- Search funnel: created → queued → claimed → settled, by status, p95 duration.
- Source matrix: rows = source_id, columns = ok/empty/failed/held, plus p95 latency.
- Queue health: depth, age, retries, DLQ, invocation count.
- D1 write health: rows/min, batch p95, failures, db size vs retention.
- Egress: gateway ready exits, 407 rate, per-exit served counts.
4. What cannot be alerted on today
Anything derived from logs, because there are 8 log lines. AL-01 (needs a stuck-search query, not a log), AL-03, AL-06, AL-08, AL-10, AL-12, AL-14 are unimplementable until the event catalogue is instrumented. This is the honest dependency: metrics follow logging, not the reverse.