The scheduler SSHed each guest directly and assumed a deployed probe script plus working root SSH at the guest's address — false for headless (nfs-export), keyless (teddycloud), mesh-only (rclone), and macOS (mac-mini) targets, which left 49 enabled checks stuck "down" on a healthy fleet. Extract the MCP run tool's resolveExecTarget into a shared internal/remote package and make it the single execution path for both the scheduler and MCP. LXC/VM checks now host-hop via pct exec / qm guest exec through the owning Proxmox host (no per-guest lan_ip, sshd, or authorized key needed); hosts and workstations resolve their address and user live, so mac-mini's `user: dtoro` is honored without a re-seed. Address preference now prefers public_ipv4 over mesh, so netbird-vps is probeable from the scheduler container. cpu_check.sh gains a real Darwin branch (it reported cpu_pct 0 before). checkdefaults.resolveSSHUser reads the top-level `user` attribute too. A machine-target resolution failure is now logged before falling back to baked config, so a broken probe-config is distinguishable from a real outage.
36 lines
1.1 KiB
Bash
36 lines
1.1 KiB
Bash
#!/usr/bin/env bash
|
|
# cpu_check.sh — CPU usage % and thermal temperature.
|
|
set -euo pipefail
|
|
|
|
os=$(uname -s)
|
|
|
|
if [ "$os" = "Darwin" ]; then
|
|
# `top -l 1 -n 0` prints "CPU usage: X% user, Y% sys, Z% idle".
|
|
# Usage is 100 minus the idle figure that precedes the literal `idle`.
|
|
USAGE=$(top -l 1 -n 0 -s 0 2>/dev/null | awk '
|
|
/^CPU usage/ {
|
|
for (i = 1; i <= NF; i++) {
|
|
if ($i == "idle") { gsub(/%/, "", $(i - 1)); printf "%.1f", 100 - $(i - 1) }
|
|
}
|
|
}' || true)
|
|
else
|
|
USAGE=$(top -bn1 2>/dev/null | awk '/^%Cpu/ {print 100 - $8}' || true)
|
|
if [ -z "$USAGE" ]; then
|
|
CORES=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)
|
|
USAGE=$(awk -v cores="$CORES" '{print ($1+$2+$3)*100/cores}' /proc/loadavg 2>/dev/null || echo "0")
|
|
fi
|
|
fi
|
|
|
|
[ -z "$USAGE" ] && USAGE=0
|
|
|
|
TEMP=""
|
|
if [ -f /sys/class/thermal/thermal_zone0/temp ]; then
|
|
TEMP=$(awk '{printf "%.1f", $1/1000}' /sys/class/thermal/thermal_zone0/temp 2>/dev/null || true)
|
|
fi
|
|
|
|
if [ -n "$TEMP" ]; then
|
|
echo "{\"health\":\"healthy\",\"metrics\":{\"cpu_pct\":$USAGE,\"cpu_temp\":$TEMP}}"
|
|
else
|
|
echo "{\"health\":\"healthy\",\"metrics\":{\"cpu_pct\":$USAGE}}"
|
|
fi
|