Probe: no access log, nothing written while reports get through. When the hub can't be reached, failed reports go to data/outage.jsonl and unsent results to data/backlog.jsonl (survives restarts). The first report that gets through uploads both and they are deleted. Hub: a probe that misses reports gets a "Not reporting" incident. When it reports again, the runs from its outage log become confirmed "Hub unreachable" incidents; the rest of the silence (probe off or restarting) is dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 KiB
CLAUDE.md
Shared context for Claude Code sessions working on this repo. This file is read on the dev machine and on each machine that runs a hub or probe (Proxmox nodes, LXCs, a Mac mini). Keep it current: when you learn something about a deployment environment, add it under "Deployment notes", and commit it.
What this is
A home network monitor with two roles, built from one repo:
-
Hub (
ROLE=hub, port 8000). FastAPI app, web UI and API.- Stores probe measurements and client devices in SQLite.
- Reads DNS data from AdGuard Home's
/control/*API (HTTP basic auth).
-
Probe (
ROLE=probe, port 8765). EveryPROBE_INTERVAL(30 s), it:- tests every other probe (ping, HTTP, a timed download), the gateway, LAN and public DNS, internet URLs and an optional VPS
- POSTs the results plus its ARP neighbors to the hub's
/api/probe/reportwith a per-probe bearer token - receives its config (peers, targets) back in the response; that's the only control channel
While reports get through, the probe writes nothing to disk except
data/probe-config.jsonwhen its config changes (uvicorn's access log is off). While the hub can't be reached (no connection, timeout, 5xx), it writes a local outage log,app/probe/outage.py:data/outage.jsonl: one line per failed reportdata/backlog.jsonl: the unsent measurements, so a restart doesn't lose them
The first report that gets through uploads the backlog and sends the failures as runs (
outagesin the report body), then both files are deleted. With noHUB_URLit is serve-only, e.g. on a VPS. -
Probe silences (
app/hub/outages.py, tableprobe_outages): when a probe misses reports for3 × interval + 10s, the hub opens an unconfirmed "Not reporting" incident. When the probe reports again, its outage runs replace that incident as confirmed "Hub unreachable" incidents; any part of the silence the log doesn't cover (the probe was off or restarting) is dropped. Probes older than this change send no runs, so their silences are always dropped: update them.
Remote: https://git.neilbantoc.dev/services/network-monitor.git (Gitea). The repo is public, so anonymous clone and fetch work and installs need no token.
- Hub installer:
https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install.sh. Confirmed: returns 200 and matchesmain. - Probe installer: the Add probe dialog fetches it from the hub (
http://<hub>:8000/install-probe.sh, open even withUI_PASSWORD), so probe installs don't depend on Gitea's raw URLs. It is also at the raw URL. - If the repo becomes private: the installers ask for a read-only
GIT_TOKENand save it in.envfor updates.
Deployment modes
| Mode | How it runs | Update command | Logs |
|---|---|---|---|
| lxc (Proxmox node) | A container made by the installer; inside it, the same as native Linux. | pct exec <ctid> -- /usr/local/bin/<name>-update (full path: pct exec runs with a minimal PATH without /usr/local/bin) |
pct exec <ctid> -- journalctl -u <name> -f |
| docker | compose.yml (hub, bridge, port 8000) / compose.probe.yml (probe, network_mode: host). The image is runtime only; the source is cloned into a volume. |
docker exec network-monitor update / docker exec network-probe update |
docker logs -f <name> |
| native, Linux | /opt/<name> is the git checkout plus .venv/, data/, .env, .native. A systemd unit <name>.service runs native/run.sh as user netmon. |
sudo <name>-update |
journalctl -u <name> -f |
| native, macOS | Same layout, owned by the installing user. The LaunchDaemon /Library/LaunchDaemons/dev.neilbantoc.<name>.plist runs the app as root: macOS 15 Local Network privacy blocks LAN connections from a daemon running as a user ([Errno 65] No route to host while curl works), and root daemons are exempt (tested on 15.3.1). |
<name>-update (no sudo; it calls sudo for launchctl kickstart) |
/opt/<name>/data/service.log |
<name> is network-monitor (hub) or network-probe. Mode defaults:
- native on macOS and inside LXC (detected with
systemd-detect-virt -c) - docker elsewhere
The mode is stored as INSTALL_MODE in /opt/<name>/.env.
The intended topology:
- Proxmox VE nodes:
lxcmode, the default whenpctand/etc/pveexist. Running the installer on the node as root creates (or reuses, found by tagnetmon-hub/netmon-probe) an unprivileged Debian LXC onvmbr0. It thenpct pushes itself into the container (re-assembled from its own functions withdeclare -f) and runs there in native mode.LXC_*variables override ID, storage, bridge, IP and size. Day to day:pct exec <ctid> -- /usr/local/bin/network-probe-update, orpct enter <ctid>and run it there.- Names and port: in an LXC (lxc mode, or native mode where
systemd-detect-virt -csays lxc),native/setup.shinstalls avahi-daemon, which announces<hostname>.local. It comments outrlimit-nprocinavahi-daemon.conf, because the stock value stops avahi-daemon from starting in unprivileged containers. The hub defaults toHOST_PORT=80there, granted byAmbientCapabilities=CAP_NET_BIND_SERVICE, unlessHOST_PORTis passed. - Inner run: lxc mode runs the inner installer with
LANG/LC_ALL=C.UTF-8(the node's locale may not exist in the container) andNETMON_NESTED=1, which shortens the inner summary. - Probe commands: Linux probes usually can't resolve
.local. When the UI is opened by a.localname, the Add probe command useshub_lan_url(the hub's own IP, native installs only) asHUB_URL. - Do not install Docker on a PVE node itself: Docker changes the host firewall, and with the Proxmox firewall on that can break guest networking.
- The first real deploy (gmktec-g9, 2026-11-05) predates
lxcmode and installed the hub with Docker on the node. The README section "Removing a Docker install from a Proxmox node" covers cleanup.
- Names and port: in an LXC (lxc mode, or native mode where
- Mac mini: native probe.
Both update commands do the same thing:
- fetch and check out the commit
- reinstall requirements if they changed
- check that
import app.mainworks - restart, and wait for
/healthzto report the new short SHA
Any failure rolls back to the previous commit. --check, --rollback and <ref> work for both. Settings live in /opt/<name>/.env; they are re-read on restart and update and never committed.
Repo map
app/main.py picks the hub or probe app by ROLE; shared lifespan (creates DATA_DIR)
app/hub/server.py FastAPI app, optional UI_PASSWORD basic auth, SPA fallback, /api/info
app/hub/probes.py probe CRUD + POST /api/probe/report (token auth) → returns probe config
app/hub/health.py matrix / strips / incidents / series from the measurements table
app/hub/outages.py probe silences: open "not reporting" incidents, settle them with the probe's outage log
app/hub/dns.py clients, query log, domains, blocked; background AdGuard discovery (60 s)
app/hub/devices.py device merge logic (MAC key, ip: fallback, IP→MAC folding)
app/hub/adguard.py AdGuard client (httpx; tests swap TRANSPORT), query log paging, base_domain
app/hub/settings.py all hub settings from env, read per call
app/hub/db.py SQLite schema (idempotent), one connection per unit of work
app/probe/server.py probe app: /probe/ping, /probe/blob, / (status JSON), the report loop
app/probe/outage.py the probe's local outage log (written only while the hub can't be reached)
app/probe/checks.py icmp (icmplib, unprivileged), http, dns (hand-built UDP query), throughput,
gateway + ARP (Linux /proc/net, macOS route/arp)
app/static/ no-build frontend: house.css/ui.js/shell.js (vendored house style, don't
edit), app.css, charts.js (SVG), common.js, views/*.js (one per page)
install.sh THE installer (both roles via NETMON_ROLE, both modes). Edit this one.
install-probe.sh GENERATED: run scripts/build-installers.sh after editing install.sh
native/ setup.sh (venv, netmon user, systemd/launchd), run.sh, update.sh, lib.sh
container/ Dockerfile, entrypoint (supervisor), update.sh, lib.sh (Docker mode)
tests/ pytest: hub API, health maths, fake AdGuard, probe checks, installers
Working on it
- Run the tests in a container. Python 3.14 in the image, code supports 3.11+:
docker run --rm -v "$PWD":/src:ro -w /src python:3.14-slim sh -c 'pip install -q -r requirements.txt -r requirements-dev.txt && python -m pytest -q -p no:cacheprovider' - Dev server:
docker compose -f compose.yml -f compose.dev.yml up --build(hub on 127.0.0.1:8000, reload on save). - After editing
install.sh: runbash scripts/build-installers.sh. A test fails ifinstall-probe.shis stale. - Keep shell scripts bash 3.2 compatible (
install.sh,native/*.sh), because macOS runs them with/bin/bash3.2:- no
mapfile, no${x,,}, no associative arrays - no
"${arr[@]}"on possibly-empty arrays underset -u - don't
source <(...) - check with
docker run --rm -v "$PWD":/src:ro bash:3.2 bash -n /src/install.sh
- no
- After any frontend change, run
bash scripts/check-js.sh. It parses every module as an ES module, the way browsers load them. Plainnode --check file.jsmissed a broken string once, and the Probes page failed to load. In UI copy, write apostrophes as ’ so a'can't end a single-quoted string. - No build step. Plain ES modules and CSS. Vendor any library into
app/static/vendor/with its version noted. - Frontend style. Follow the house style: toolbar → content → status bar per screen, house classes/tokens, sentence-case copy. Put user and API strings into the DOM with
textContentonly (el()does this). NeverreplaceChildren(null); usefill()fromcommon.js. - Startup work goes in
lifespan, never at import.updateimportsapp.mainas a pre-flight check. - Don't remove
DATA_DIR.mkdir(parents=True, exist_ok=True)inapp/main.py. The scaffold'sverify.shpatches that exact line to simulate a startup crash. - New settings: add to
app/hub/settings.pyand.env.example, or for probes.env.probe.example(andKEYSininstall.shif the installer should accept them). - New dependencies: pin
==X.Y.*inrequirements.txt. Prefer pure-Python wheels: native mode installs them on Debian 12/13 and macOS.
Debugging a deployment
Start with these:
- Probe status:
curl -s http://127.0.0.1:8765/. It showsregistered,peers,icmp,gateway,last_errorandbuffered. - Hub health:
curl -s http://127.0.0.1:8000/healthz - Hub config as the UI sees it:
curl -s http://127.0.0.1:8000/api/info
Common problems:
icmp: falseon Linux:sysctl net.ipv4.ping_group_rangemust include the service's group, e.g.0 2147483647. Re-run the installer as root; it writes/etc/sysctl.d/60-network-probe-ping.conf.registered: false: the token is unknown to the hub (the probe was removed there). Add the probe again and re-run its install command.- Peers time out:
- Check that the address the hub recorded is the probe's LAN IP. A probe reaching the hub through a NAT or proxy may report the wrong one; set
ADVERTISE_ADDRin the probe's.env, or the address on its page in the UI. - Check firewalls on 8765/tcp.
- Check that the address the hub recorded is the probe's LAN IP. A probe reaching the hub through a NAT or proxy may report the wrong one; set
- Native service won't start:
systemctl status <name>,journalctl -u <name> -n 100. On macOS:sudo launchctl print system/dev.neilbantoc.<name>anddata/service.log. - Python too old for native mode: needs 3.11+. Debian 11 / Ubuntu 22.04 are too old; use Docker mode or a newer template.
- AdGuard pages show an error: check
ADGUARD_URL(the web UI address, e.g.http://ip:3000or:80) and credentials, then restart the hub.
Status and what is untested
What has been tested:
- The tests and the scaffold's
verify.sh(Docker mode: build, install, update, refuse, rollback) pass. - End to end on Linux Docker: hub + two probes + a stand-in AdGuard.
- Native mode on Debian 12 under systemd, simulating an LXC (Python 3.11):
- installs
- ping fixed by the sysctl
- update, refuse, rollback
- survives a reboot
- re-run keeps
.env
Never run on real hardware yet. Note what you find under "Deployment notes" below:
- an actual Proxmox node:
lxcmode against realpct/pveam/pvesm(tested with stubs that record the calls), and native mode inside a real unprivileged LXC, including the ping range limited to the container's mapped groups - macOS: launchd, Homebrew Python,
route/arpparsing on a live system, the application firewall - a real AdGuard Home (only tested against a stand-in built from its API docs)
Deployment notes
Add environment-specific findings here (machine, date, what happened, fix).
- gmktec-g9 (Proxmox VE node), 2026-11-05: the installer run on the node picked Docker mode, because
lxcmode didn't exist yet, and installed Docker on the node. Fixed: Proxmox nodes now default tolxcmode. To clean up, see the README section "Removing a Docker install from a Proxmox node".