Files
vpn-dns-gateway/monitoring/README.md
T
billandClaude Opus 5.5 d3a5e6bc73
vpn-dns-gateway/pipeline/head This commit looks good
Add Prometheus/Grafana monitoring stack (refs #19)
Assignment 7 (instructor manual v1.42, Chapter 5): Prometheus, Grafana OSS,
Node Exporter and Blackbox Exporter beside Gitea/Jenkins on The-Ocean, pinned
by tag and digest, memory-capped for the 1 GiB droplet, no host ports.

- monitoring/: compose, scrape and probe config, Grafana provisioning
  (data source, Group 1 SRE dashboard, two alert rules, Discord contact
  point via env var), README with deploy/backup/rollback and runbooks,
  EVIDENCE.md with the deploy, capacity and exposure test records.
- deploy/: private probe network (172.30.90.0/28) with Caddy aliases;
  ci allowlist admits only the Blackbox address 172.30.90.10; new
  metrics.yebilly.me route behind the same allowlist.
- manual images: DNS record, Discord webhook, contact-point test, dashboard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 11:11:02 -04:00

6.6 KiB

Monitoring (Assignment 7 / Instructor Manual Chapter 5)

Prometheus, Grafana OSS, Node Exporter, and Blackbox Exporter on the droplet The-Ocean, beside Gitea, Jenkins, and Caddy (deploy/). Grafana is the only web entry point: https://metrics.yebilly.me (same allowlist as Jenkins, then Grafana login). No monitoring port is published on the host.

Service Image (pinned in compose.yaml) Private address Networks Memory cap State
Prometheus prom/prometheus:v3.15.1 prometheus:9090 monitoring 128 MiB volume monitoring_prometheus_data (7 d / 500 MB)
Grafana OSS grafana/grafana:13.2.5 grafana:3000 monitoring, gitea_web 192 MiB volume monitoring_grafana_data
Node Exporter quay.io/prometheus/node-exporter:v1.12.1 node-exporter:9100 monitoring 32 MiB none (read-only host /)
Blackbox Exporter quay.io/prometheus/blackbox-exporter:v0.29.1 blackbox-exporter:9115, 172.30.90.10 monitoring, gitea_probe 32 MiB none

Configuration in Git: prometheus/prometheus.yml, blackbox/blackbox.yml, grafana/provisioning/ (data source, dashboard provider, alert rules, contact point), and grafana/dashboards/sre.json. Provisioned items are read-only in the UI; change them here, copy to the droplet, and restart Grafana.

Secrets (never in Git)

~/monitoring/.env.secret on the droplet, mode 600, owner root:

GF_SECURITY_ADMIN_PASSWORD=<from the team password manager>
DISCORD_WEBHOOK_URL=<webhook for #devops-alerts>

The admin password applies only when Grafana first creates its database; later changes are made in Grafana and recorded in the password manager.

Deploy

Prerequisite: deploy/ is current on the droplet and Caddy has been recreated once (cd ~/gitea && docker compose up -d caddy), which creates the gitea_probe network and the metrics.yebilly.me route.

scp -r monitoring root@<droplet-ip>:~/monitoring        # from the laptop
cd ~/monitoring && chmod 700 .
# scp from Windows creates 700 directories; Grafana (uid 472) must read its config.
find grafana prometheus blackbox -type d -exec chmod 755 {} + && find grafana prometheus blackbox -type f -exec chmod 644 {} +
install -m 600 /dev/null .env.secret && nano .env.secret  # typed by a team member
docker compose config --quiet
docker compose pull
docker compose run --rm --no-deps --entrypoint /bin/promtool prometheus check config /etc/prometheus/prometheus.yml
docker compose up -d
docker compose ps
docker compose logs --tail=50 prometheus grafana node-exporter blackbox-exporter
docker image inspect --format '{{.RepoDigests}}' prom/prometheus:v3.15.1   # repeat per image

Startup order does not matter: Grafana retries the data source and Prometheus retries scrapes. All four services restart unless-stopped.

Operate, update, back up, roll back

  • Pause/resume: docker compose stop / docker compose start. Never docker compose down -v; it deletes both named volumes.

  • Config change: edit in Git, copy the file, then docker compose restart prometheus (or grafana). Validate Prometheus config with the promtool line above first.

  • Upgrade one image at a time: back up, read the release notes, change the tag and digest in compose.yaml, docker compose pull <svc> && docker compose up -d <svc>, then check targets, dashboard, and alert rules. Do not assume an older Grafana or Prometheus can read data written by a newer one: restore the backup instead.

  • Contact-point test (the provisioned contact point has no Test button in the UI; Grafana 13 removed the old test endpoint). Sends one message to #devops-alerts using the stored URL, which is never printed:

    GIP=$(docker inspect monitoring-grafana-1 --format '{{(index .NetworkSettings.Networks "monitoring_monitoring").IPAddress}}')
    P=$(docker exec monitoring-grafana-1 printenv GF_SECURITY_ADMIN_PASSWORD)
    curl -s -u "billy:$P" -H 'Content-Type: application/json' -X POST \
      -d '{"integration":{"uid":"team-alerts-discord","type":"discord","version":"v1","settings":{},"secureFields":{"url":true}}}' \
      "http://$GIP:3000/apis/notifications.alerting.grafana.app/v1beta1/namespaces/default/receivers/dGVhbS1hbGVydHM/test"
    unset P   # expect {"status":"success",...}; dGVhbS1hbGVydHM is base64 of "team-alerts"
    
  • Backup (state not rebuildable from Git: Grafana users/passwords, alert state, metric history):

    cd ~/monitoring && docker compose stop grafana prometheus
    docker run --rm -v monitoring_grafana_data:/g:ro -v monitoring_prometheus_data:/p:ro \
      -v /root/backups:/b alpine tar czf /b/monitoring-$(date -u +%Y%m%dT%H%M%SZ).tgz /g /p
    docker compose start grafana prometheus
    
  • Remove the stack entirely: docker compose stop && docker compose rm -f (volumes kept), then revert the metrics block and probe allowlist entry in deploy/Caddyfile and recreate Caddy.

Runbook: HTTPS service down

Alert HTTPS service down (critical, owner Billy, backup Vincent): a login page's probe_success has been 0 for 1 minute, or the probe series is missing.

  1. Acknowledge in #devops-alerts with your name and the time.
  2. Open the Group 1 SRE dashboard. Is only one service down, or both?
    • Both down, and the scrape health panel also shows failures: check Caddy and the droplet first.
    • Missing data rather than 0: the monitoring stack itself is failing (docker compose ps in ~/monitoring).
  3. On the droplet: cd ~/gitea && docker compose ps, then docker compose logs --tail=50 <gitea|jenkins|caddy>.
  4. If the service container is stopped: docker compose start <service>. If it is running but unhealthy: docker compose restart <service>. Never use down -v.
  5. Confirm the probe returns to 1 and Discord shows the resolved message. For Jenkins, also run a pipeline and confirm the Gitea status check.
  6. Record the timeline in the incident log or manual.

Runbook: Root disk space low

Alert Root disk space low (warning, owner Billy): available space on / (/dev/vda1, ext4) has stayed below 15% for 5 minutes. 15% of 24.9 GB is about 3.7 GB: enough to act before Gitea, Jenkins, or Prometheus fail to write.

  1. Acknowledge in #devops-alerts.
  2. df -h / and docker system df to find the growth.
  3. Safe first actions: docker builder prune (build cache), journalctl --vacuum-size=200M, remove obsolete images with docker image prune. Do not delete volumes.
  4. Prometheus is capped at 500 MB / 7 days; if it is the cause, lower the cap rather than deleting its volume.
  5. If space cannot be recovered, plan a disk resize (permanent, costs more) with the team.