# Thor Out-of-band host and cluster health for the LotusGuild cluster. **Status: planning.** There is no code yet. See the "Plan Thor" issue. ## Why On 2026-11-23, compute-storage-01 was caught in an OOM loop, which stalled Ceph across the cluster. - hwmonDaemon, running on that host, never noticed. - Gandalf, the network monitor, misread the symptoms as a network failure (Tinker 615797777, gandalf#57). A monitor that runs on a failing host is least reliable exactly when it's needed. Thor watches the servers from outside. ## Who owns what | App | Owns | Rule | |---|---|---| | **gandalf** | Networking: switches, links, WAN, modem, and later checking from several places | "Is the network the problem?" | | **hwmonDaemon** | What only the host itself can read: SMART, NVMe wear, ECC/EDAC, the hardware event log, kernel hardware errors, disk firmware | "Only the box knows this." | | **thor** | Host and cluster health seen from outside, using Prometheus, Loki, the Proxmox API and Ceph | "Someone else has to notice this." | **Test for any new check:** if node_exporter or Loki already exposes the data, it belongs to thor. If only the host can read it, it belongs to hwmonDaemon. If it's the network, it belongs to gandalf. ## Planned scope (to be refined) - **Host health:** - memory exhaustion and OOM kills, naming the guest that caused them - CPU saturation - hosts that are stalled rather than down - **Proxmox:** HA events, guests that crash-loop, and guest storage use. This takes over hwmonDaemon's LXC storage check. - **Ceph:** one cluster-wide view instead of the same warning reported from every node (hwmonDaemon #29, #35). - **One ticket per root cause:** group the symptoms of one incident, auto-resolve with a note, and handle recurring or expected conditions (hwmonDaemon #31, #33). ## Principles - **Run off the hardware it watches.** Not on a cluster node, and preferably not on the same box as Gandalf. - **One incident, one ticket.** A shared dedupe contract between gandalf, hwmonDaemon and thor, so the three apps never open three tickets for one event. - **A ticket cutter and correlator, not a dashboard.** Grafana already draws the graphs. ## Related - hwmonDaemon#39: interim OOM check, which moves here later. - hwmonDaemon#40: the boundary, and which checks move here. - gandalf#57: Gandalf stops calling non-network faults "network". ## Code layout - `thor/config.py`: settings from `/etc/thor/thor.json` (non-secret) and `/etc/thor/*.env` (secrets). - `thor/clients/`: read-only clients for Prometheus, Loki, Proxmox and Gandalf, and the Tinker ticket client. A source that can't answer raises `SourceError`, which means "unknown", never "nothing found". - `thor/db.py`: MariaDB (CT 149, schema `thor`), versioned migrations, and the queries. - `thor/monitor.py`: the 120 s loop (`thor-monitor.service`): review window since the last good cycle with 24 h catch-up, blind periods per source, writes buffered while the database is away. - `thor/web/`: `thor.service`: `/health` (database + monitor freshness + deployed commit) and `/metrics`. The decisions behind all of this are in the plan on thor#1. ## Development ```bash python3 -m venv .venv && .venv/bin/pip install -r requirements.txt -r requirements-dev.txt .venv/bin/python -m pytest # unit tests .venv/bin/flake8 . && .venv/bin/bandit -q -r thor -ll # Database tests need a throwaway MariaDB: THOR_TEST_DB_HOST=127.0.0.1 THOR_TEST_DB_PASSWORD=... .venv/bin/python -m pytest tests/test_db_mariadb.py ``` CI (`.gitea/workflows/ci.yml`, modelled on Pulse's) runs lint, the dash check, tests with coverage, the MariaDB tests, bandit, pip-audit, gitleaks, actionlint, shellcheck, zizmor and semgrep on every pull request, and deploys `main`. ## Deploy Thor runs on **CT 173** (`thor`, 10.10.10.86, DHCP reservation), in the HA rule `EMERGENCY needed`. | Path | What | |---|---| | `/opt/thor/app` | checkout of this repo (detached at the deployed commit) | | `/opt/thor/venv` | Python virtualenv | | `/opt/thor/revision.env` | `THOR_SHA`, the commit `/health` reports | | `/etc/thor/thor.json` | non-secret settings (`deploy/thor.example.json`) | | `/etc/thor/*.env` | secrets: `pve.env`, `db.env`, `gandalf.env`, `tinker.env` (root:thor 0640, never in git) | | `/etc/webhook/hooks.json` | deploy hook and its HMAC secret (also the repo secret `WEBHOOK_SECRET`) | - **First install:** `bash deploy/bootstrap.sh` inside the CT (idempotent). - **Every merge to main:** CI signs `{ref, sha, ts}` and calls the webhook on `:9000`. `/usr/local/bin/thor_deploy.sh` (installed from `deploy/thor_deploy.sh`; reinstall it by hand when it changes) checks out exactly that commit, installs dependencies, units and the nginx site, restarts `thor` and `thor-monitor`, and rolls back unless `/health` reports the commit with a working database. CI then waits for production to report the commit. Log: `/var/log/thor-deploy.log`. - **After a deploy:** prod HEAD, `systemctl is-active thor thor-monitor`, `curl http://10.10.10.86/health`, and no tracebacks in `journalctl -u thor -u thor-monitor`.