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

+2 -1
View File
@@ -43,13 +43,14 @@ def init_app(app: Flask) -> None:
},
)
from scrobbler.api import apps, auth, sessions, stats, tokens
from scrobbler.api import apps, auth, health, sessions, stats, tokens
api.register_blueprint(auth.blp, url_prefix="/api/v1/auth")
api.register_blueprint(apps.blp, url_prefix="/api/v1/apps")
api.register_blueprint(sessions.blp, url_prefix="/api/v1/sessions")
api.register_blueprint(tokens.blp, url_prefix="/api/v1/tokens")
api.register_blueprint(stats.blp, url_prefix="/api/v1/me")
api.register_blueprint(health.blp)
from scrobbler.openapi import lastfm
+28
View File
@@ -0,0 +1,28 @@
from flask_smorest import Blueprint, abort
from marshmallow import Schema, fields
from sqlalchemy import text
from scrobbler.extensions import db
from scrobbler.schemas import ErrorSchema
blp = Blueprint("Health", __name__, description="Liveness for load balancers and containers")
class HealthSchema(Schema):
status = fields.String(metadata={"example": "ok"})
@blp.route("/healthz", methods=["GET"])
@blp.response(200, HealthSchema)
@blp.alt_response(503, schema=ErrorSchema, description="The database is unreachable")
def healthz():
"""Health check
Returns 200 when the API can reach its database.
"""
try:
db.session.execute(text("SELECT 1"))
except Exception:
db.session.rollback()
abort(503, code="database_unavailable", message="The database is unreachable")
return {"status": "ok"}