- Refactor executeCheck to return checkResult struct with metrics map - Add ping check kind (ICMP reachability via system ping, macOS+Linux) - Add ssh-script check kind (remote host exec via SSH, allowlisted scripts) - Add threshold evaluation (warn/crit per metric from check config JSONB) - Add inode tracking to disk check - All 4 existing checks now return structured metrics - 17 check scripts: cpu, memory, load, swap, disk_usage, disk_smart, updates, zfs, process, uptime, oom, journal, time, fd, docker_health, caddy_error_rate, backup_freshness - Auto-deploy via tools/setup-checks.sh -> checks/install.sh on git pull - Add ping to OpenAPI CheckKind enum and generated Go types
23 lines
787 B
Bash
23 lines
787 B
Bash
#!/usr/bin/env bash
|
|
# swap_check.sh — swap usage percentage.
|
|
set -euo pipefail
|
|
|
|
if [ -r /proc/meminfo ]; then
|
|
SWAP_TOTAL=$(awk '/^SwapTotal:/ {printf "%d", $2}' /proc/meminfo)
|
|
SWAP_FREE=$(awk '/^SwapFree:/ {printf "%d", $2}' /proc/meminfo)
|
|
elif [ "$(uname)" = "Darwin" ]; then
|
|
SP=$(sysctl vm.swapusage 2>/dev/null | awk '{print $4, $9}' | tr -d 'M' || echo "0 0")
|
|
SWAP_TOTAL=$(echo "$SP" | awk '{printf "%.0f", $1*1024}')
|
|
SWAP_FREE=$(echo "$SP" | awk '{printf "%.0f", ($1-$2)*1024}')
|
|
else
|
|
SWAP_TOTAL=0
|
|
SWAP_FREE=0
|
|
fi
|
|
|
|
if [ "$SWAP_TOTAL" -eq 0 ]; then
|
|
echo "{\"health\":\"healthy\",\"metrics\":{\"swap_pct\":0}}"
|
|
else
|
|
USED_PCT=$(awk "BEGIN {printf \"%.1f\", (1 - $SWAP_FREE/$SWAP_TOTAL)*100}")
|
|
echo "{\"health\":\"healthy\",\"metrics\":{\"swap_pct\":$USED_PCT}}"
|
|
fi
|