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

+574
View File
@@ -0,0 +1,574 @@
{
"uid": "scrobbler-usage",
"title": "Scrobbler: Usage",
"description": "Who is using the service and how much they're listening.",
"tags": [
"scrobbler"
],
"timezone": "browser",
"editable": true,
"graphTooltip": 1,
"refresh": "30s",
"time": {
"from": "now-6h",
"to": "now"
},
"schemaVersion": 41,
"version": 1,
"templating": {
"list": []
},
"annotations": {
"list": []
},
"links": [
{
"type": "dashboards",
"tags": [
"scrobbler"
],
"asDropdown": true,
"title": "Scrobbler",
"includeVars": false
}
],
"panels": [
{
"type": "row",
"title": "Now",
"id": 1,
"collapsed": false,
"gridPos": {
"x": 0,
"y": 0,
"w": 24,
"h": 1
},
"panels": []
},
{
"type": "stat",
"title": "Scrobbles in the last 24h",
"description": "",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(increase(scrobbler_scrobbles_total{result=\"accepted\"}[24h]))",
"legendFormat": "__auto",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short",
"decimals": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "text",
"value": null
}
]
}
},
"overrides": []
},
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"colorMode": "value",
"graphMode": "area",
"textMode": "auto",
"justifyMode": "auto"
},
"id": 2,
"gridPos": {
"x": 0,
"y": 1,
"w": 6,
"h": 5
}
},
{
"type": "stat",
"title": "Users",
"description": "",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "max(scrobbler_users)",
"legendFormat": "__auto",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "text",
"value": null
}
]
}
},
"overrides": []
},
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"colorMode": "value",
"graphMode": "area",
"textMode": "auto",
"justifyMode": "auto"
},
"id": 3,
"gridPos": {
"x": 6,
"y": 1,
"w": 6,
"h": 5
}
},
{
"type": "stat",
"title": "Active in the last 24h",
"description": "Users with at least one scrobble in the last 24 hours.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "max(scrobbler_active_users{window=\"24h\"})",
"legendFormat": "__auto",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "text",
"value": null
}
]
}
},
"overrides": []
},
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"colorMode": "value",
"graphMode": "area",
"textMode": "auto",
"justifyMode": "auto"
},
"id": 4,
"gridPos": {
"x": 12,
"y": 1,
"w": 6,
"h": 5
}
},
{
"type": "stat",
"title": "Listening now",
"description": "",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "max(scrobbler_now_playing_active)",
"legendFormat": "__auto",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "text",
"value": null
}
]
}
},
"overrides": []
},
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"colorMode": "value",
"graphMode": "area",
"textMode": "auto",
"justifyMode": "auto"
},
"id": 5,
"gridPos": {
"x": 18,
"y": 1,
"w": 6,
"h": 5
}
},
{
"type": "row",
"title": "Listening",
"id": 6,
"collapsed": false,
"gridPos": {
"x": 0,
"y": 6,
"w": 24,
"h": 1
},
"panels": []
},
{
"type": "timeseries",
"title": "Scrobbles / min",
"description": "",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(rate(scrobbler_scrobbles_total{result=\"accepted\"}[$__rate_interval])) * 60",
"legendFormat": "accepted",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short",
"custom": {
"lineWidth": 2,
"fillOpacity": 10,
"showPoints": "never",
"spanNulls": true
},
"min": 0
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"id": 7,
"gridPos": {
"x": 0,
"y": 7,
"w": 12,
"h": 8
}
},
{
"type": "timeseries",
"title": "Listening now",
"description": "",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "max(scrobbler_now_playing_active)",
"legendFormat": "users playing a track",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short",
"custom": {
"lineWidth": 2,
"fillOpacity": 10,
"showPoints": "never",
"spanNulls": true
},
"min": 0
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"id": 8,
"gridPos": {
"x": 12,
"y": 7,
"w": 12,
"h": 8
}
},
{
"type": "timeseries",
"title": "Scrobbles per day",
"description": "",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(increase(scrobbler_scrobbles_total{result=\"accepted\"}[1d]))",
"legendFormat": "scrobbles",
"refId": "A",
"interval": "1d"
}
],
"fieldConfig": {
"defaults": {
"unit": "short",
"custom": {
"lineWidth": 1,
"fillOpacity": 70,
"showPoints": "never",
"spanNulls": true,
"drawStyle": "bars"
},
"min": 0
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"timeFrom": "30d",
"id": 9,
"gridPos": {
"x": 0,
"y": 15,
"w": 24,
"h": 8
}
},
{
"type": "row",
"title": "People",
"id": 10,
"collapsed": false,
"gridPos": {
"x": 0,
"y": 23,
"w": 24,
"h": 1
},
"panels": []
},
{
"type": "timeseries",
"title": "Active users",
"description": "Distinct users scrobbling within each window.",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "max by (window) (scrobbler_active_users)",
"legendFormat": "{{window}}",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"unit": "short",
"custom": {
"lineWidth": 2,
"fillOpacity": 10,
"showPoints": "never",
"spanNulls": true
},
"min": 0
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"id": 11,
"gridPos": {
"x": 0,
"y": 24,
"w": 12,
"h": 8
}
},
{
"type": "timeseries",
"title": "Sign-ups and web logins",
"description": "",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(increase(scrobbler_registrations_total[$__rate_interval]))",
"legendFormat": "registrations",
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(increase(scrobbler_ui_logins_total{result=\"success\"}[$__rate_interval]))",
"legendFormat": "logins",
"refId": "B"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(increase(scrobbler_ui_logins_total{result=\"failure\"}[$__rate_interval]))",
"legendFormat": "failed logins",
"refId": "C"
}
],
"fieldConfig": {
"defaults": {
"unit": "short",
"custom": {
"lineWidth": 1,
"fillOpacity": 70,
"showPoints": "never",
"spanNulls": true,
"drawStyle": "bars"
},
"min": 0
},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"id": 12,
"gridPos": {
"x": 12,
"y": 24,
"w": 12,
"h": 8
}
}
]
}