summaryrefslogtreecommitdiff
path: root/statuspage/checks/hw.sh
blob: bc0c6695bb8e90688a2d69afc360dbfe02666add (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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"