diff options
| author | batsumaru <> | 2026-07-01 15:38:51 +0900 |
|---|---|---|
| committer | batsumaru <> | 2026-07-01 15:38:51 +0900 |
| commit | dfec6df2fb876fadb20d24a5bd8f4b4400a0f659 (patch) | |
| tree | 3fc126f5bbaeef31b3a7a6d3e2afda968473c9b9 /statuspage/checks/hw.sh | |
Split monolithic status check.sh into modular check scripts
Replace the single-file prototype with independently-addable check
scripts (checks/*.sh) that each emit JSONL rows, a shared helper lib,
and one orchestrator/renderer (render.sh) that groups rows by section
and writes the static status page. A broken check script now shows up
as a down/warn row instead of crashing the whole render.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'statuspage/checks/hw.sh')
| -rw-r--r-- | statuspage/checks/hw.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/statuspage/checks/hw.sh b/statuspage/checks/hw.sh new file mode 100644 index 0000000..bc0c669 --- /dev/null +++ b/statuspage/checks/hw.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# checks/hw.sh +# Hardware/host metrics: load avg, uptime, free mem, zroot usage, zpool health. +set -eu + +DIR=$(dirname "$0") +. "$DIR/../lib/common.sh" + +LOAD=$(sysctl -n vm.loadavg | tr -d '{}' | sed 's/^ *//;s/ *$//') +json_line "hardware" "load avg" "$LOAD" "ok" + +UPTIME=$(uptime | sed 's/.*up //;s/,.*load.*//') +json_line "hardware" "uptime" "$UPTIME" "ok" + +MEM_FREE=$(sysctl -n vm.stats.vm.v_free_count) +MEM_PAGE=$(sysctl -n hw.pagesize) +MEM_FREE_MB=$((MEM_FREE * MEM_PAGE / 1024 / 1024)) +json_line "hardware" "free mem" "${MEM_FREE_MB} MB" "ok" + +DISK=$(df -h /zroot 2>/dev/null | awk 'NR==2{print $5}') +DISK_PCT=${DISK%\%} +if [ -z "$DISK_PCT" ]; then + DISK_STATUS="warn" + DISK="unknown" +elif [ "$DISK_PCT" -ge 90 ]; then + DISK_STATUS="down" +elif [ "$DISK_PCT" -ge 75 ]; then + DISK_STATUS="warn" +else + DISK_STATUS="ok" +fi +json_line "hardware" "zroot usage" "$DISK" "$DISK_STATUS" + +if ZPOOL=$(zpool status -x 2>&1); then + case "$ZPOOL" in + "all pools are healthy") ZPOOL_STATUS="ok" ;; + *) ZPOOL_STATUS="warn" ;; + esac +else + ZPOOL_STATUS="down" +fi +json_line "hardware" "zpool" "$ZPOOL" "$ZPOOL_STATUS" |
