diff --git a/monitoring/.env b/monitoring/.env new file mode 100644 index 0000000..13f17f1 --- /dev/null +++ b/monitoring/.env @@ -0,0 +1,4 @@ +PROMETHEUS_TAG=v3.15.1 +GRAFANA_TAG=13.3.0 +NODE_EXPORTER_TAG=v1.12.1 +BLACKBOX_TAG=v0.29.1 diff --git a/monitoring/README.md b/monitoring/README.md new file mode 100644 index 0000000..44d5399 --- /dev/null +++ b/monitoring/README.md @@ -0,0 +1,26 @@ +# Monitoring (Prometheus + Grafana) for the SSW590 droplet + +Deployed at `/opt/startup/monitoring` with `docker compose up -d`. + +| Container | Image (pinned) | Port (private only) | +|---|---|---| +| prometheus | prom/prometheus:v3.15.1 | 9090 | +| grafana | grafana/grafana:13.3.0 | 3000 (via Caddy as https://metrics.ssw590.abrdns.com) | +| node-exporter | quay.io/prometheus/node-exporter:v1.12.1 | 9100 | +| blackbox-exporter | quay.io/prometheus/blackbox-exporter:v0.29.1 | 9115 | + +- `.env` holds image tags only (no secrets). +- `prometheus/prometheus.yml`: 30 s scrapes; jobs prometheus, node, blackbox, https (Gitea and Jenkins login pages via Blackbox). +- `blackbox/blackbox.yml`: `http_2xx` module, IPv4, TLS verification on. +- `grafana/provisioning/`: data source (uid dg2y8czei4y68b) and dashboard provider. +- `grafana/dashboards/ssw590-ops.json`: team dashboard (versioned definition). +- `grafana/alert-rules-export.yaml`: sanitized export of the two Grafana-managed alert rules. +- Grafana is attached to the existing `startup_private` network so Caddy can reach `grafana:3000`; Prometheus and exporters stay on the `monitoring` network. +- Secrets (Grafana admin password, Discord webhook URL) are not in Git. + +Validate before (re)starting: +``` +docker compose config --quiet +docker compose run --rm --no-deps --entrypoint /bin/promtool prometheus check config /etc/prometheus/prometheus.yml +``` +See RUNBOOK.md for alert response and rollback. diff --git a/monitoring/RUNBOOK.md b/monitoring/RUNBOOK.md new file mode 100644 index 0000000..a7a030e --- /dev/null +++ b/monitoring/RUNBOOK.md @@ -0,0 +1,31 @@ +# SSW590 monitoring runbook + +Owner: Shubham Bhayana (SB). Verifier/backup: Sandya Devanahally (SD). +Alerts go to the `team-alerts` Grafana contact point (team Discord channel; webhook URL kept outside Git). +Dashboard: https://metrics.ssw590.abrdns.com/d/ssw590-ops + +## Alert: HTTPS service unavailable (severity: critical) +Fires per service when `probe_success{job="https"}` stays 0 for 1 minute, or when the series is missing. + +1. Acknowledge in the alert channel ("ack - investigating"). +2. Open the dashboard; confirm which service is DOWN and whether the other one is still UP. +3. On the droplet: `cd /opt/startup && docker compose ps`. If the service is stopped, `docker compose start `; if running but unhealthy, `docker compose logs --tail=100 `. +4. If both probes fail, check Caddy (`docker compose logs --tail=50 caddy`), DNS and the certificate. +5. If only monitoring is affected (no data), check `cd /opt/startup/monitoring && docker compose ps` and the Prometheus targets (`up`). +6. Recovery is confirmed when `probe_success` returns 1 and the RESOLVED notification arrives. Then run one Jenkins build and check the Gitea login page. +7. Record start/ack/restore times in the incident notes. + +## Alert: Root filesystem free space below 15% (severity: warning) +Fires when available/size for the host root filesystem (/dev/vda1, ext4, /) stays below 15% for 5 minutes. 15% leaves room for logs, image pulls and Jenkins workspaces on a 25 GB disk before services fail. + +1. `df -h /` and `docker system df` on the droplet. +2. Remove unused images: `docker image prune` (never `docker compose down -v`; it deletes data volumes). +3. Clean old Jenkins workspaces/builds; check `/var/lib/docker/containers/*/*-json.log` sizes. +4. If still low, plan a disk/volume resize and open a Gitea issue. + +## Restore / rollback +- Monitoring config lives in `monitoring/` in this repository and on the droplet at `/opt/startup/monitoring`. +- Pause: `docker compose stop` / `docker compose start`. Do not use `down -v`. +- Roll back a config change: restore the previous file from Git (or `compose.yaml.bak`), `docker compose config --quiet`, then `docker compose up -d `. +- State that is not in Git: the `monitoring_prometheus_data` and `monitoring_grafana_data` volumes (Grafana users, contact point, alert rules). Back up with + `docker run --rm -v monitoring_grafana_data:/d -v $PWD:/b alpine tar czf /b/grafana-data.tgz -C /d .` while Grafana is stopped. diff --git a/monitoring/blackbox/blackbox.yml b/monitoring/blackbox/blackbox.yml new file mode 100644 index 0000000..bf8c456 --- /dev/null +++ b/monitoring/blackbox/blackbox.yml @@ -0,0 +1,9 @@ +modules: + http_2xx: + prober: http + timeout: 10s + http: + method: GET + preferred_ip_protocol: ip4 + tls_config: + insecure_skip_verify: false diff --git a/monitoring/compose.yaml b/monitoring/compose.yaml new file mode 100644 index 0000000..374cd25 --- /dev/null +++ b/monitoring/compose.yaml @@ -0,0 +1,55 @@ +services: + prometheus: + image: prom/prometheus:${PROMETHEUS_TAG:?choose a release} + restart: unless-stopped + command: + - --config.file=/etc/prometheus/prometheus.yml + - --storage.tsdb.path=/prometheus + - --storage.tsdb.retention.time=7d + volumes: + - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro + - prometheus_data:/prometheus + networks: [monitoring] + + grafana: + image: grafana/grafana:${GRAFANA_TAG:?choose a release} + restart: unless-stopped + environment: + GF_AUTH_ANONYMOUS_ENABLED: "false" + GF_USERS_ALLOW_SIGN_UP: "false" + GF_SERVER_ROOT_URL: "https://metrics.ssw590.abrdns.com/" + volumes: + - grafana_data:/var/lib/grafana + - ./grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards:ro + - ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources:ro + - ./grafana/dashboards:/var/lib/grafana/dashboards:ro + networks: [monitoring, proxy] + + node-exporter: + image: quay.io/prometheus/node-exporter:${NODE_EXPORTER_TAG:?choose a release} + restart: unless-stopped + pid: host + command: + - --path.rootfs=/host + - --path.procfs=/host/proc + - --path.sysfs=/host/sys + volumes: + - /:/host:ro,rslave + networks: [monitoring] + + blackbox-exporter: + image: quay.io/prometheus/blackbox-exporter:${BLACKBOX_TAG:?choose a release} + restart: unless-stopped + command: ["--config.file=/config/blackbox.yml"] + volumes: + - ./blackbox/blackbox.yml:/config/blackbox.yml:ro + networks: [monitoring] + +networks: + monitoring: + proxy: + external: true + name: startup_private +volumes: + prometheus_data: + grafana_data: diff --git a/monitoring/grafana/alert-rules-export.yaml b/monitoring/grafana/alert-rules-export.yaml new file mode 100644 index 0000000..71b0f42 --- /dev/null +++ b/monitoring/grafana/alert-rules-export.yaml @@ -0,0 +1,120 @@ +apiVersion: 1 +groups: + - orgId: 1 + name: ssw-590-30s + folder: SSW590 + interval: 30s + rules: + - uid: fg2yd76uk00sga + title: HTTPS service unavailable + condition: C + data: + - refId: A + relativeTimeRange: + from: 600 + to: 0 + datasourceUid: dg2y8czei4y68b + model: + editorMode: code + expr: probe_success{job="https"} + instant: true + intervalMs: 1000 + legendFormat: __auto + maxDataPoints: 43200 + range: false + refId: A + - refId: C + queryType: expression + datasourceUid: __expr__ + model: + conditions: + - evaluator: + params: + - 1 + type: lt + operator: + type: and + query: + params: + - C + reducer: + params: [] + type: last + type: query + datasource: + type: __expr__ + uid: __expr__ + expression: A + intervalMs: 1000 + maxDataPoints: 43200 + refId: C + type: threshold + noDataState: Alerting + execErrState: Alerting + for: 1m + annotations: + description: 'Check: docker compose ps in /opt/startup; restart the failed service; verify login page and probe_success returns 1.' + runbook_url: https://git.ssw590.abrdns.com/StartupTeam/Strartup-product/src/branch/feature/monitoring/monitoring/RUNBOOK.md + summary: '{{ $labels.instance }} HTTPS probe failing for 1 minute' + labels: + owner: shubham + severity: critical + isPaused: false + notification_settings: + receiver: team-alerts + - uid: dg2ydl5gwz474e + title: Root filesystem free space below 15% + condition: C + data: + - refId: A + relativeTimeRange: + from: 600 + to: 0 + datasourceUid: dg2y8czei4y68b + model: + editorMode: code + expr: ' 100 * node_filesystem_avail_bytes{device="/dev/vda1",fstype="ext4",mountpoint="/",job="node"} / node_filesystem_size_bytes{device="/dev/vda1",fstype="ext4",mountpoint="/",job="node"}' + instant: true + intervalMs: 1000 + legendFormat: __auto + maxDataPoints: 43200 + range: false + refId: A + - refId: C + queryType: expression + datasourceUid: __expr__ + model: + conditions: + - evaluator: + params: + - 15 + type: lt + operator: + type: and + query: + params: + - C + reducer: + params: [] + type: last + type: query + datasource: + type: __expr__ + uid: __expr__ + expression: A + intervalMs: 1000 + maxDataPoints: 43200 + refId: C + type: threshold + noDataState: Alerting + execErrState: Alerting + for: 5m + annotations: + description: 'Check: df -h /; docker system df; remove unused images (docker image prune) and old build workspaces; resize volume if still low.' + summary: Root filesystem on SSW590-Droplet has less than 15% free + labels: + owner: shubham + severity: warning + isPaused: false + notification_settings: + receiver: team-alerts diff --git a/monitoring/grafana/dashboards/ssw590-ops.json b/monitoring/grafana/dashboards/ssw590-ops.json new file mode 100644 index 0000000..bf2f666 --- /dev/null +++ b/monitoring/grafana/dashboards/ssw590-ops.json @@ -0,0 +1,568 @@ +{ + "uid": "ssw590-ops", + "title": "SSW590 Startup Operations", + "tags": [ + "ssw590", + "sre" + ], + "timezone": "America/New_York", + "time": { + "from": "now-6h", + "to": "now" + }, + "refresh": "30s", + "schemaVersion": 41, + "version": 1, + "editable": true, + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "panels": [ + { + "id": 1, + "type": "timeseries", + "title": "Droplet CPU utilization (%)", + "description": "Whole-droplet CPU busy %, averaged across all CPUs: 100 x (1 - idle rate). node_cpu_seconds_total is a counter, so rate() is used, never the raw total.", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "gridPos": { + "x": 0, + "y": 0, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "expr": "100 * (1 - avg(rate(node_cpu_seconds_total{job=\"node\",mode=\"idle\"}[$__rate_interval])))", + "legendFormat": "CPU busy %" + } + ], + "fieldConfig": { + "defaults": { + "unit": "percent", + "custom": { + "lineWidth": 2, + "fillOpacity": 10, + "showPoints": "never", + "thresholdsStyle": { + "mode": "line" + } + }, + "min": 0, + "max": 100, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "orange", + "value": 70 + }, + { + "color": "red", + "value": 90 + } + ] + } + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi" + } + } + }, + { + "id": 2, + "type": "timeseries", + "title": "Available host memory (bytes)", + "description": "MemAvailable: kernel estimate of memory available to applications without swapping (not just unused RAM). Unit: bytes (IEC). Host total is about 961 MiB.", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "gridPos": { + "x": 12, + "y": 0, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "expr": "node_memory_MemAvailable_bytes{job=\"node\"}", + "legendFormat": "MemAvailable" + } + ], + "fieldConfig": { + "defaults": { + "unit": "bytes", + "custom": { + "lineWidth": 2, + "fillOpacity": 10, + "showPoints": "never", + "thresholdsStyle": { + "mode": "line" + } + }, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "red", + "value": null + }, + { + "color": "orange", + "value": 104857600 + }, + { + "color": "green", + "value": 209715200 + } + ] + } + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi" + } + } + }, + { + "id": 3, + "type": "timeseries", + "title": "Root filesystem free space (%)", + "description": "Available bytes / size bytes for the verified host root filesystem only (/dev/vda1, ext4, mounted at /). /boot, /boot/efi, overlay and pseudo filesystems are excluded. Alert line at 15%.", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "gridPos": { + "x": 0, + "y": 8, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "expr": "100 * node_filesystem_avail_bytes{device=\"/dev/vda1\",fstype=\"ext4\",mountpoint=\"/\",job=\"node\"} / node_filesystem_size_bytes{device=\"/dev/vda1\",fstype=\"ext4\",mountpoint=\"/\",job=\"node\"}", + "legendFormat": "/ free %" + } + ], + "fieldConfig": { + "defaults": { + "unit": "percent", + "custom": { + "lineWidth": 2, + "fillOpacity": 10, + "showPoints": "never", + "thresholdsStyle": { + "mode": "line" + } + }, + "min": 0, + "max": 100, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "red", + "value": null + }, + { + "color": "orange", + "value": 15 + }, + { + "color": "green", + "value": 25 + } + ] + } + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi" + } + } + }, + { + "id": 4, + "type": "timeseries", + "title": "Gitea HTTPS availability (probe_success)", + "description": "Blackbox http_2xx probe of the Gitea login page through Caddy: DNS, valid TLS, redirects followed, final 2xx. 1 = UP, 0 = DOWN.", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "gridPos": { + "x": 12, + "y": 8, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "expr": "probe_success{job=\"https\",instance=\"https://git.ssw590.abrdns.com/user/login\"}", + "legendFormat": "Gitea" + } + ], + "fieldConfig": { + "defaults": { + "unit": "none", + "custom": { + "lineWidth": 2, + "fillOpacity": 10, + "showPoints": "never", + "thresholdsStyle": { + "mode": "line" + }, + "lineInterpolation": "stepAfter" + }, + "min": 0, + "max": 1, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "red", + "value": null + }, + { + "color": "green", + "value": 1 + } + ] + }, + "mappings": [ + { + "type": "value", + "options": { + "0": { + "text": "DOWN", + "color": "red" + }, + "1": { + "text": "UP", + "color": "green" + } + } + } + ] + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi" + } + } + }, + { + "id": 5, + "type": "timeseries", + "title": "Jenkins HTTPS availability (probe_success)", + "description": "Blackbox http_2xx probe of the Jenkins login page through Caddy. 1 = UP, 0 = DOWN. Login-page success does not prove a working build.", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "gridPos": { + "x": 0, + "y": 16, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "expr": "probe_success{job=\"https\",instance=\"https://ci.ssw590.abrdns.com/login\"}", + "legendFormat": "Jenkins" + } + ], + "fieldConfig": { + "defaults": { + "unit": "none", + "custom": { + "lineWidth": 2, + "fillOpacity": 10, + "showPoints": "never", + "thresholdsStyle": { + "mode": "line" + }, + "lineInterpolation": "stepAfter" + }, + "min": 0, + "max": 1, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "red", + "value": null + }, + { + "color": "green", + "value": 1 + } + ] + }, + "mappings": [ + { + "type": "value", + "options": { + "0": { + "text": "DOWN", + "color": "red" + }, + "1": { + "text": "UP", + "color": "green" + } + } + } + ] + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi" + } + } + }, + { + "id": 6, + "type": "timeseries", + "title": "HTTPS probe duration (seconds)", + "description": "Total Blackbox probe time per service (DNS + connect + TLS + HTTP), one line per service.", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "gridPos": { + "x": 12, + "y": 16, + "w": 12, + "h": 8 + }, + "targets": [ + { + "refId": "A", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "expr": "probe_duration_seconds{job=\"https\",instance=\"https://git.ssw590.abrdns.com/user/login\"}", + "legendFormat": "Gitea" + }, + { + "refId": "B", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "expr": "probe_duration_seconds{job=\"https\",instance=\"https://ci.ssw590.abrdns.com/login\"}", + "legendFormat": "Jenkins" + } + ], + "fieldConfig": { + "defaults": { + "unit": "s", + "custom": { + "lineWidth": 2, + "fillOpacity": 10, + "showPoints": "never", + "thresholdsStyle": { + "mode": "line" + } + }, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "orange", + "value": 1 + }, + { + "color": "red", + "value": 5 + } + ] + } + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi" + } + } + }, + { + "id": 7, + "type": "timeseries", + "title": "Scrape health (up)", + "description": "Collection health: 1 = Prometheus scraped the target. For the https job, up=1 only means the probe ran; probe_success shows whether the site answered.", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "gridPos": { + "x": 0, + "y": 24, + "w": 24, + "h": 7 + }, + "targets": [ + { + "refId": "A", + "datasource": { + "type": "prometheus", + "uid": "dg2y8czei4y68b" + }, + "expr": "up", + "legendFormat": "{{job}} {{instance}}" + } + ], + "fieldConfig": { + "defaults": { + "unit": "none", + "custom": { + "lineWidth": 2, + "fillOpacity": 10, + "showPoints": "never", + "thresholdsStyle": { + "mode": "line" + }, + "lineInterpolation": "stepAfter" + }, + "min": 0, + "max": 1, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "red", + "value": null + }, + { + "color": "green", + "value": 1 + } + ] + }, + "mappings": [ + { + "type": "value", + "options": { + "0": { + "text": "DOWN", + "color": "red" + }, + "1": { + "text": "UP", + "color": "green" + } + } + } + ] + }, + "overrides": [] + }, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi" + } + } + } + ] +} diff --git a/monitoring/grafana/provisioning/dashboards/ssw590.yaml b/monitoring/grafana/provisioning/dashboards/ssw590.yaml new file mode 100644 index 0000000..597ad1b --- /dev/null +++ b/monitoring/grafana/provisioning/dashboards/ssw590.yaml @@ -0,0 +1,8 @@ +apiVersion: 1 +providers: + - name: ssw590 + folder: SSW590 + type: file + allowUiUpdates: true + options: + path: /var/lib/grafana/dashboards diff --git a/monitoring/grafana/provisioning/datasources/prometheus.yaml b/monitoring/grafana/provisioning/datasources/prometheus.yaml new file mode 100644 index 0000000..76eff0d --- /dev/null +++ b/monitoring/grafana/provisioning/datasources/prometheus.yaml @@ -0,0 +1,9 @@ +apiVersion: 1 +datasources: + - name: prometheus + uid: dg2y8czei4y68b + type: prometheus + access: proxy + url: http://prometheus:9090 + isDefault: true + editable: true diff --git a/monitoring/prometheus/prometheus.yml b/monitoring/prometheus/prometheus.yml new file mode 100644 index 0000000..0539ca8 --- /dev/null +++ b/monitoring/prometheus/prometheus.yml @@ -0,0 +1,23 @@ +global: + scrape_interval: 30s +scrape_configs: + - job_name: prometheus + static_configs: [{targets: ["prometheus:9090"]}] + - job_name: node + static_configs: [{targets: ["node-exporter:9100"]}] + - job_name: blackbox + static_configs: [{targets: ["blackbox-exporter:9115"]}] + - job_name: https + metrics_path: /probe + params: {module: [http_2xx]} + static_configs: + - targets: + - https://git.ssw590.abrdns.com/user/login + - https://ci.ssw590.abrdns.com/login + relabel_configs: + - source_labels: [__address__] + target_label: __param_target + - source_labels: [__param_target] + target_label: instance + - target_label: __address__ + replacement: blackbox-exporter:9115