diff options
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" |
