Monitoring stack, containers and dashboards
CI / lint (push) Successful in 9s
CI / test (push) Successful in 36s
CI / notify (push) Successful in 5s

- API image (uv multi-stage, non-root, gunicorn, migrations on start,
  health check) and UI image (nginx, CSP, config.js rendered from
  API_BASE_URL); /healthz documented in OpenAPI
- docker compose runs db, api and ui; the "monitoring" profile adds
  Prometheus, postgres-exporter and Grafana, all provisioned from files
- Grafana dashboards: API overview (RED), Last.fm API, Usage, Database
- Prometheus alert rules: API down, error rate, latency, auth failure
  spike, ignored scrobbles, DB pool saturation, Postgres down
- Pool checkout gauge counts events (the pool's own counters lag the
  checkin event); error ratios show 0 instead of "No data"
- Tests check dashboards and alerts only use metrics that exist
- scripts/generate_traffic.py drives realistic traffic for demos

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
mattandClaude Opus 5.5 committed 2026-09-25 14:26:19 +01:00
1 parent faa74871a5
commit ea705589f1
28 files changed
+3508 -14

No files matched your search

+21 -10
View File
@@ -34,15 +34,26 @@ def instrument(engine: Engine) -> None:
stack.pop()
pool = engine.pool
if not hasattr(pool, "size"): # e.g. NullPool in tools: nothing worth reporting
return
checked_out = metrics.db_pool_connections.labels(state="checked_out")
overflow = metrics.db_pool_connections.labels(state="overflow")
metrics.db_pool_connections.labels(state="size").set(pool.size())
def _report_pool(*_args):
# QueuePool exposes these; other pools (e.g. NullPool in tools) don't.
if not hasattr(pool, "checkedout"):
return
metrics.db_pool_connections.labels(state="checked_out").set(pool.checkedout())
metrics.db_pool_connections.labels(state="idle").set(pool.checkedin())
metrics.db_pool_connections.labels(state="overflow").set(max(0, pool.overflow()))
metrics.db_pool_connections.labels(state="size").set(pool.size())
# Pool events fire before the pool updates its own counters, so reading
# pool.checkedout() inside them is off by one; count the events instead.
@event.listens_for(pool, "checkout")
def _checkout(*_args):
checked_out.inc()
for name in ("connect", "checkout", "checkin", "close"):
event.listen(pool, name, _report_pool)
@event.listens_for(pool, "checkin")
def _checkin(*_args):
checked_out.dec()
@event.listens_for(pool, "connect")
def _connect(*_args):
overflow.set(max(0, pool.overflow()))
@event.listens_for(pool, "close")
def _close(*_args):
overflow.set(max(0, pool.overflow()))