Add the locked pricing service, trusted-agent pipeline, Ansible deployments, security gates, recovery runbooks, prerequisite evidence, and preparation manual. Prepared with Codex assistance. Vincent explicitly authorized this local commit and will handle the push. Assessed releases and recovery exercises remain pending.
152 lines
8.1 KiB
Markdown
152 lines
8.1 KiB
Markdown
# Monitoring (Assignment 7 / Instructor Manual Chapter 5)
|
|
|
|
Assignment 8 prepares a production pricing `/health` target and Grafana panel
|
|
in the versioned configuration. Apply those additions only after the service
|
|
is healthy; they are not yet deployed. See `../delivery/RUNBOOKS.md`.
|
|
|
|
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. At
|
|
first login, change it in Grafana (Profile → Change password), store the new
|
|
value in the password manager, and delete the `GF_SECURITY_ADMIN_PASSWORD`
|
|
line from `.env.secret`; on The-Ocean this was done on 28 Oct 2026.
|
|
|
|
## 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.
|
|
|
|
```bash
|
|
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:
|
|
|
|
```bash
|
|
GIP=$(docker inspect monitoring-grafana-1 --format '{{(index .NetworkSettings.Networks "monitoring_monitoring").IPAddress}}')
|
|
read -rs -p 'Grafana password for billy: ' P; echo # typed, never stored
|
|
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):
|
|
|
|
```bash
|
|
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:3.22 tar czf /b/monitoring-$(date -u +%Y%m%dT%H%M%SZ).tgz /g /p
|
|
docker compose start grafana prometheus
|
|
```
|
|
|
|
Restore (same image versions only): `docker compose stop grafana prometheus`,
|
|
empty both volumes, then
|
|
`docker run --rm -v monitoring_grafana_data:/g -v monitoring_prometheus_data:/p -v /root/backups:/b alpine:3.22 tar xzf /b/monitoring-<stamp>.tgz -C /`
|
|
and `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: Monitoring target down
|
|
|
|
Alert `Monitoring target down` (critical, owner Billy, backup Vincent): a
|
|
Prometheus scrape target (`up`) has failed for 1 minute, or no target data
|
|
exists. While it fires, the dashboard and the other alerts are partly blind.
|
|
|
|
1. Acknowledge in `#devops-alerts` with your name and the time.
|
|
2. The `job` label names the broken collector: `blackbox` or `https` means
|
|
Blackbox Exporter, `node` means Node Exporter, `prometheus` means Prometheus.
|
|
3. On the droplet: `cd ~/monitoring && docker compose ps`, then
|
|
`docker compose logs --tail=50 <service>`.
|
|
4. Stopped: `docker compose start <service>`. Running but failing:
|
|
`docker compose restart <service>`. Never use `down -v`.
|
|
5. Confirm all targets are up again (dashboard *Scrape health* panel) and that
|
|
Discord shows the resolved message.
|
|
|
|
## 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. If the probe series disappears
|
|
instead, this rule can resolve; `Monitoring target down` reports that case.
|
|
|
|
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.
|