Monitoring stack, containers and dashboards
- 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:
1 parent
faa74871a5
commit
ea705589f1
28 files changed
+3508
-14
No files matched your search
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
# Apply database migrations (unless RUN_MIGRATIONS=0), then start the given command.
|
||||
set -e
|
||||
if [ "${RUN_MIGRATIONS:-1}" = "1" ]; then
|
||||
# Not under gunicorn, so don't use (or pollute) the multiprocess metrics directory.
|
||||
env -u PROMETHEUS_MULTIPROC_DIR flask --app scrobbler db upgrade
|
||||
fi
|
||||
exec "$@"
|
||||
@@ -0,0 +1,29 @@
|
||||
# Scrobbler API: gunicorn serving the Flask app, metrics on :9100.
|
||||
FROM ghcr.io/astral-sh/uv:0.7.21 AS uv
|
||||
|
||||
FROM python:3.13-slim AS build
|
||||
COPY --from=uv /uv /usr/local/bin/uv
|
||||
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy UV_PYTHON_DOWNLOADS=never
|
||||
WORKDIR /app
|
||||
COPY pyproject.toml uv.lock ./
|
||||
RUN uv sync --locked --no-dev --no-install-project
|
||||
COPY src ./src
|
||||
RUN uv sync --locked --no-dev --no-editable
|
||||
|
||||
FROM python:3.13-slim
|
||||
RUN useradd --system --uid 10001 --no-create-home scrobbler
|
||||
WORKDIR /app
|
||||
COPY --from=build /app/.venv /app/.venv
|
||||
COPY gunicorn.conf.py docker/api-entrypoint.sh ./
|
||||
ENV PATH=/app/.venv/bin:$PATH \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PROMETHEUS_MULTIPROC_DIR=/tmp/scrobbler-metrics \
|
||||
BIND=0.0.0.0:8000 \
|
||||
METRICS_PORT=9100 \
|
||||
OPENAPI_DOCS_ENABLED=1
|
||||
USER scrobbler
|
||||
EXPOSE 8000 9100
|
||||
HEALTHCHECK --interval=15s --timeout=3s --start-period=20s \
|
||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=2)"
|
||||
ENTRYPOINT ["./api-entrypoint.sh"]
|
||||
CMD ["gunicorn", "-c", "gunicorn.conf.py"]
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Point the UI at the API: rewrite config.js from $API_BASE_URL at container start.
|
||||
set -e
|
||||
case "$API_BASE_URL" in
|
||||
http://*|https://*) ;;
|
||||
*) echo "API_BASE_URL must start with http:// or https://" >&2; exit 1 ;;
|
||||
esac
|
||||
url=$(printf '%s' "$API_BASE_URL" | sed 's#/*$##; s#["\\]##g')
|
||||
cat > /usr/share/nginx/html/config.js <<JS
|
||||
window.SCROBBLER_CONFIG = {
|
||||
apiBaseUrl: "$url",
|
||||
};
|
||||
JS
|
||||
@@ -0,0 +1,8 @@
|
||||
# Scrobbler web UI: static files served by nginx.
|
||||
FROM nginx:1.29-alpine
|
||||
ENV API_BASE_URL=http://localhost:5050
|
||||
COPY deploy/nginx/default.conf.template /etc/nginx/templates/default.conf.template
|
||||
COPY docker/ui-config.sh /docker-entrypoint.d/40-scrobbler-config.sh
|
||||
COPY frontend /usr/share/nginx/html
|
||||
EXPOSE 80
|
||||
HEALTHCHECK --interval=15s --timeout=3s CMD wget -qO- http://127.0.0.1/login.html >/dev/null || exit 1
|
||||
Reference in new issue
Block a user