blob: 384ab4a58c477cb78106e3d300ca37f1020706ba (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#!/bin/sh
# checks/hw.sh
# Hardware/host metrics: load avg, uptime, free mem, zroot usage, and per
# pool health/capacity plus scrub/error status for every zpool on the box.
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"
BOOT=$(sysctl -n kern.boottime | sed -n 's/{ sec = \([0-9]*\).*/\1/p')
SECS=$(($(date +%s) - BOOT))
UP_D=$((SECS / 86400))
UP_H=$(((SECS % 86400) / 3600))
UP_M=$(((SECS % 3600) / 60))
json_line "hardware" "uptime" "${UP_D}d ${UP_H}h ${UP_M}m" "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"
for pool in $(zpool list -H -o name 2>/dev/null); do
HEALTH=$(zpool list -H -o health "$pool" 2>/dev/null)
CAP=$(zpool list -H -o capacity "$pool" 2>/dev/null)
case "$HEALTH" in
ONLINE) POOL_STATUS="ok" ;;
DEGRADED) POOL_STATUS="warn" ;;
*) POOL_STATUS="down" ;;
esac
json_line "hardware" "zpool $pool" "$HEALTH, ${CAP} used" "$POOL_STATUS"
STATUS_OUT=$(zpool status "$pool" 2>/dev/null) || STATUS_OUT=""
SCAN=$(printf '%s\n' "$STATUS_OUT" | sed -n 's/^[[:space:]]*scan: //p')
ERRORS=$(printf '%s\n' "$STATUS_OUT" | sed -n 's/^[[:space:]]*errors: //p')
case "$ERRORS" in
"No known data errors") ERR_STATUS="ok" ;;
"") ERR_STATUS="warn" ;;
*) ERR_STATUS="down" ;;
esac
json_line "hardware" "zpool $pool scrub" "${SCAN:-never scrubbed}" "$ERR_STATUS"
done
|