rewrite as a daemon with shutdown on low battery
the oneshot+timer produced 8367 journal lines a day of systemd start/stop noise. now Type=notify with an internal ticker, logging transitions only. hardware sits behind sensor.Sensor; internal/monitor is pure, so the shutdown state machine is tested without a pi. four guards, each tested, because a false poweroff of a box with no physical access is worse than a missed one: - a failed read resets the arming window rather than pausing it - voltage must actually fall across the window, else it is a stuck sensor. this is the only defence against the ac line reading 0 while mains is connected, so it is load-bearing - a settle period stops a restart loop acting on early readings - flapping ac cannot accumulate verified on hardware 2026-08-09: after poweroff on battery the x1208 starts the pi again when mains returns, with no button press. that was the risk that could have made this feature unsafe. a failed tick rewrites the previous sample with sensor_healthy 0 and the failure counter, so last_update still freezes for the staleness alert while the failure stays visible. module path moved to git.mial.net. debian units and the compose overlay deleted; deployment lives in the infra repo.
This commit is contained in:
@@ -1,23 +1,40 @@
|
||||
# x1208-exporter — Geekworm X1208 UPS HAT exporter
|
||||
#
|
||||
# Deployment lives in the rpi.mial.net repo. There are no deploy recipes here.
|
||||
|
||||
default:
|
||||
@just --list
|
||||
|
||||
# Compile everything
|
||||
build:
|
||||
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o build/x1208-exporter ./...
|
||||
go build ./...
|
||||
|
||||
deploy: build
|
||||
scp build/x1208-exporter rpi:/tmp/x1208-exporter
|
||||
scp systemd/x1208-exporter.service systemd/x1208-exporter.timer rpi:/tmp/
|
||||
ssh rpi 'sudo install -m 0755 /tmp/x1208-exporter /usr/local/bin/x1208-exporter && \
|
||||
sudo install -m 0644 /tmp/x1208-exporter.service /etc/systemd/system/ && \
|
||||
sudo install -m 0644 /tmp/x1208-exporter.timer /etc/systemd/system/ && \
|
||||
sudo install -d -m 0755 -o root /var/lib/node-exporter/textfiles && \
|
||||
sudo systemctl daemon-reload && \
|
||||
sudo systemctl enable --now x1208-exporter.timer && \
|
||||
sudo systemctl start x1208-exporter.service && \
|
||||
cat /var/lib/node-exporter/textfiles/x1208.prom'
|
||||
# Run the test suite (all pure packages; the hardware packages need a Pi)
|
||||
test:
|
||||
go test ./...
|
||||
|
||||
logs:
|
||||
ssh rpi 'journalctl -u x1208-exporter.service -n 30 --no-pager'
|
||||
test-verbose:
|
||||
go test -v ./...
|
||||
|
||||
run-once:
|
||||
ssh rpi 'sudo systemctl start x1208-exporter.service && cat /var/lib/node-exporter/textfiles/x1208.prom'
|
||||
# Static checks
|
||||
lint:
|
||||
go vet ./...
|
||||
gofmt -l .
|
||||
|
||||
fmt:
|
||||
gofmt -w .
|
||||
|
||||
# Build the Nix package exactly as the Pi will
|
||||
nix-build:
|
||||
nix build .#x1208-exporter
|
||||
|
||||
# Run the daemon against a scripted sensor. Touches no hardware and powers
|
||||
# nothing off — the shutdown command is replaced with an echo.
|
||||
run-fake out="/tmp/x1208.prom":
|
||||
go run . -fake -interval 1s -out {{ out }} \
|
||||
-shutdown -shutdown-settle-ticks 2 -shutdown-samples 3 \
|
||||
-shutdown-cmd "/usr/bin/env echo POWEROFF-WOULD-RUN"
|
||||
|
||||
# Print the metrics the fake run produced
|
||||
show out="/tmp/x1208.prom":
|
||||
@cat {{ out }}
|
||||
|
||||
Reference in New Issue
Block a user