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
@@ -0,0 +1,65 @@
|
||||
groups:
|
||||
- name: scrobbler
|
||||
rules:
|
||||
- alert: ScrobblerDown
|
||||
expr: up{job="scrobbler-api"} == 0
|
||||
for: 2m
|
||||
labels: {severity: critical}
|
||||
annotations:
|
||||
summary: Scrobbler API metrics endpoint is down
|
||||
description: Prometheus hasn't been able to scrape {{ $labels.instance }} for 2 minutes.
|
||||
|
||||
- alert: HighErrorRate
|
||||
expr: |
|
||||
sum(rate(scrobbler_http_requests_total{status=~"5.."}[5m]))
|
||||
/ sum(rate(scrobbler_http_requests_total[5m])) > 0.05
|
||||
for: 5m
|
||||
labels: {severity: critical}
|
||||
annotations:
|
||||
summary: More than 5% of API requests are failing
|
||||
description: 5xx ratio is {{ $value | humanizePercentage }}.
|
||||
|
||||
- alert: HighLatency
|
||||
expr: |
|
||||
histogram_quantile(0.95,
|
||||
sum by (le) (rate(scrobbler_http_request_duration_seconds_bucket[5m]))) > 1
|
||||
for: 10m
|
||||
labels: {severity: warning}
|
||||
annotations:
|
||||
summary: API p95 latency is above 1s
|
||||
description: p95 latency is {{ $value | humanizeDuration }}.
|
||||
|
||||
- alert: AuthFailureSpike
|
||||
expr: sum(rate(scrobbler_auth_failures_total[5m])) > 10
|
||||
for: 5m
|
||||
labels: {severity: warning}
|
||||
annotations:
|
||||
summary: Unusually many authentication failures
|
||||
description: "{{ $value | humanize }} failures/s: check for a misconfigured client or credential stuffing."
|
||||
|
||||
- alert: ScrobbleIgnoreRateHigh
|
||||
expr: |
|
||||
sum(rate(scrobbler_scrobbles_total{result="ignored"}[15m]))
|
||||
/ sum(rate(scrobbler_scrobbles_total[15m])) > 0.2
|
||||
for: 15m
|
||||
labels: {severity: warning}
|
||||
annotations:
|
||||
summary: More than 20% of scrobbles are being ignored
|
||||
description: A client may be sending bad timestamps or empty metadata.
|
||||
|
||||
- alert: DBPoolExhausted
|
||||
expr: |
|
||||
sum(scrobbler_db_pool_connections{state="checked_out"})
|
||||
>= sum(scrobbler_db_pool_connections{state="size"})
|
||||
for: 5m
|
||||
labels: {severity: warning}
|
||||
annotations:
|
||||
summary: Every pooled database connection is in use
|
||||
description: Workers are running on overflow connections; requests may queue.
|
||||
|
||||
- alert: PostgresDown
|
||||
expr: pg_up == 0
|
||||
for: 2m
|
||||
labels: {severity: critical}
|
||||
annotations:
|
||||
summary: Postgres is unreachable from postgres-exporter
|
||||
@@ -0,0 +1,19 @@
|
||||
global:
|
||||
scrape_interval: 15s
|
||||
evaluation_interval: 15s
|
||||
|
||||
rule_files:
|
||||
- alerts.yml
|
||||
|
||||
scrape_configs:
|
||||
- job_name: scrobbler-api
|
||||
static_configs:
|
||||
- targets: ["api:9100"]
|
||||
|
||||
- job_name: postgres
|
||||
static_configs:
|
||||
- targets: ["postgres-exporter:9187"]
|
||||
|
||||
- job_name: prometheus
|
||||
static_configs:
|
||||
- targets: ["localhost:9090"]
|
||||
Reference in new issue
Block a user