From dfec6df2fb876fadb20d24a5bd8f4b4400a0f659 Mon Sep 17 00:00:00 2001 From: batsumaru <> Date: Wed, 1 Jul 2026 15:38:51 +0900 Subject: 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 --- statuspage/checks/hw.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 statuspage/checks/hw.sh (limited to 'statuspage/checks/hw.sh') 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" -- cgit v1.3