# Observability — Prometheus & Grafana (errors.bitreport.pt) **Audience:** DevOps, SRE. **Scope:** Two processes expose **`GET /metrics`** in Prometheus text format: | Service | Typical scrape URL | Metric prefix (node defaults) | |---------|-------------------|-------------------------------| | Hub API (`api/`) | `http://:3200/metrics` | `er_api_*`, plus domain gauges `er_*` | | Ingest API (`ingest-api/`) | `http://:/metrics` | `er_ingest_*` | Scrape **both** targets in Prometheus; use Grafana for dashboards and alerts. --- ## 1. Scraping configuration (Prometheus) Add two `static_configs` jobs (names are examples): ```yaml scrape_configs: - job_name: errors_hub_api metrics_path: /metrics static_configs: - targets: ['10.10.50.x:3200'] labels: service: errors_hub env: production - job_name: errors_ingest_api metrics_path: /metrics static_configs: - targets: ['10.10.50.y:3210'] labels: service: errors_ingest env: production ``` If TLS or auth is fronted by Nginx, scrape the **internal** listener or enable mTLS/network policy as per your standard. --- ## 2. Hub API — key metrics ### HTTP traffic - **`er_api_http_requests_total`** — labels: `method`, `route`, `status_code`. - **`er_api_http_request_duration_seconds`** — histogram for latency SLOs. - **`er_api_rate_limit_rejections_total`** — labels: `bucket` (`global`, `ingest`, `login`, `mutation`). Increments when `@fastify/rate-limit` returns 429 (or 403 when ban applies) for that policy. Use alongside `status_code="429"` on the HTTP counter to alert on abuse vs. organic load. ### Domain gauges (refreshed when **`GET /api/error-monitoring/stats`** runs) Automation or Grafana can **poll** that endpoint on an interval (with read key) to keep gauges warm, **or** you rely on natural admin/UI traffic. | Metric | Labels | Meaning | |--------|--------|---------| | `er_incidents_total` | `state` | Count by `open`, `investigating`, `resolved`, `ignored` | | `er_incidents_by_severity` | `severity` | Count by severity | | `er_occurrences_last_24h` | — | Occurrence rows in last 24h | | `er_resolved_last_24h` | — | Distinct incidents resolved in last 24h | | `er_project_incidents_total` | `project`, `state` | Per-project counts | | `er_project_resolution_rate` | `project` | Resolved ÷ total (0..1) | ### Node/process defaults `collectDefaultMetrics` runs with prefix `er_api_` — includes event loop delay, heap, GC, etc. Use for generic health. --- ## 3. Ingest API — key metrics | Metric | Labels | Meaning | |--------|--------|---------| | `er_ingest_request_duration_seconds` | `status_code` | End-to-end POST latency (SLO: watch p95/p99) | | `er_ingest_requests_total` | `status_code` | Request volume by outcome class | | `er_ingest_events_total` | `outcome`, `rule_id` | `stored` / `error` use empty `rule_id`; `skipped_noise` sets noise policy id (e.g. `resize_observer_loop`) | | `er_ingest_batch_size` | — | Histogram of events per request | | `er_ingest_active_connections` | — | In-flight requests (gauge) | Plus `er_ingest_*` process defaults from `prom-client`. --- ## 4. Grafana — starter panels 1. **Ingest availability:** `sum(rate(er_ingest_requests_total[5m])) by (status_code)`. 2. **Ingest latency:** histogram quantiles on `er_ingest_request_duration_seconds` (e.g. `histogram_quantile(0.95, …)`). 3. **Noise vs stored:** `rate(er_ingest_events_total{outcome="stored"}[5m])` vs `skipped_noise`. Per-rule noise: `sum(rate(er_ingest_events_total{outcome="skipped_noise"}[5m])) by (rule_id)`. 4. **Open incidents:** `er_incidents_total` by `state` (after stats refresh). 5. **Hub HTTP errors:** `sum(rate(er_api_http_requests_total{status_code=~"5.."}[5m]))`. --- ## 5. Linking to the observability “stats” stream The hub’s **`GET /api/error-monitoring/stats`** JSON payload is the **operational summary** humans use; Prometheus mirrors a subset as **gauges** when that route is called. For Grafana: - Prefer **metrics** for trends and alerting. - Use the **JSON endpoint** (with `api_key`) for ad-hoc checks or scripted reports — see [HTTP_CONTRACTS.md](HTTP_CONTRACTS.md). --- ## Related - [HTTP_CONTRACTS.md](HTTP_CONTRACTS.md) — curl examples including `/metrics`. - [RUNBOOK_INGEST_DEBUG.md](RUNBOOK_INGEST_DEBUG.md) — 429 / auth aligned with `er_ingest_*`.