scheduler: add ping + ssh-script check kinds, metrics refactor, 17 host check scripts
- 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
This commit is contained in:
27
checks/memory_check.sh
Normal file
27
checks/memory_check.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
# memory_check.sh — RAM usage percentage.
|
||||
set -euo pipefail
|
||||
|
||||
TOTAL=1
|
||||
AVAIL=1
|
||||
|
||||
if [ -r /proc/meminfo ]; then
|
||||
TOTAL=$(awk '/^MemTotal:/ {printf "%d", $2}' /proc/meminfo)
|
||||
AVAIL=$(awk '/^MemAvailable:/ {printf "%d", $2}' /proc/meminfo)
|
||||
elif [ "$(uname)" = "Darwin" ]; then
|
||||
MEM=$(vm_stat 2>/dev/null | awk '
|
||||
/page size/ {ps=$8}
|
||||
/Pages free/ {free+=$NF}
|
||||
/Pages active/ {active+=$NF}
|
||||
/Pages wired/ {wired+=$NF}
|
||||
END {printf "%.2f %.2f", ps*(free+active+wired)/1048576, ps*wired/1048576}')
|
||||
TOTAL=$(echo "$MEM" | awk '{printf "%.0f", $1}')
|
||||
AVAIL=$(echo "$MEM" | awk '{printf "%.0f", $1 - $2}')
|
||||
fi
|
||||
|
||||
if [ "$TOTAL" -eq 0 ]; then TOTAL=1; fi
|
||||
if [ "$AVAIL" -lt 0 ]; then AVAIL=0; fi
|
||||
|
||||
USED_PCT=$(awk "BEGIN {printf \"%.1f\", (1 - $AVAIL/$TOTAL)*100}")
|
||||
|
||||
echo "{\"health\":\"healthy\",\"metrics\":{\"mem_pct\":$USED_PCT}}"
|
||||
Reference in New Issue
Block a user