C.W.K.
Stream
Lesson 10 of 14 · published

Fleet Monitoring

~18 min · monitoring, morning-check, cron

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

The 30-second morning check

A fleet you can't see is a fleet that drifts. The simplest possible monitoring: a script that SSHs to every machine, prints a one-line status (uptime, disk, memory, load), and tells you which machines are unreachable. Run it manually each morning, or schedule it via cron/launchd to email you the result.

What to actually check

  • Reachability — can you SSH at all? (counts as a heartbeat)
  • Uptime — has anything rebooted unexpectedly?
  • Disk — is anyone above 85%?
  • Load — any CPU pinned?
  • Memory pressure — anyone swapping hard?

Code

morning-check.sh·bash
#!/bin/bash
# morning-check.sh — fleet health snapshot
set -u

HOSTS_FILE="${1:-$HOME/.fleet/all.txt}"
UNREACHABLE=0

echo "================================================"
echo " Fleet Health — $(date '+%Y-%m-%d %H:%M')"
echo "================================================"

while IFS= read -r host; do
    [[ -z "$host" || "$host" =~ ^# ]] && continue
    printf '\n--- %-12s ' "$host"

    if result=$(ssh -o ConnectTimeout=5 -o BatchMode=yes "$host" '
        echo OK
        uptime | sed "s/.*up/up/; s/, [0-9]* user.*//"
        df -h / | tail -1 | awk "{print \$5 \" used, \" \$4 \" free\"}"
        sysctl -n vm.loadavg 2>/dev/null | tr -d "{}"
    ' 2>/dev/null); then
        echo "$result" | tail -n +2
    else
        echo "UNREACHABLE"
        UNREACHABLE=$((UNREACHABLE + 1))
    fi
done < "$HOSTS_FILE"

echo ""
echo "================================================"
echo " Unreachable: $UNREACHABLE"
echo "================================================"
Schedule it (launchd on macOS)·xml
<!-- ~/Library/LaunchAgents/com.user.fleet-check.plist -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
  "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.user.fleet-check</string>
  <key>ProgramArguments</key>
  <array>
    <string>/Users/you_username/dotfiles/scripts/morning-check.sh</string>
  </array>
  <key>StartCalendarInterval</key>
  <dict>
    <key>Hour</key><integer>8</integer>
    <key>Minute</key><integer>0</integer>
  </dict>
  <key>StandardOutPath</key>
  <string>/tmp/fleet-check.log</string>
  <key>StandardErrorPath</key>
  <string>/tmp/fleet-check.err</string>
</dict>
</plist>
Load the launchd job·bash
launchctl load ~/Library/LaunchAgents/com.user.fleet-check.plist

# View the latest output
cat /tmp/fleet-check.log

# Unload
launchctl unload ~/Library/LaunchAgents/com.user.fleet-check.plist

External links

Exercise

Save the morning-check script in your dotfiles' scripts/ directory. Run it once manually. If output looks right, schedule it via launchd (or cron on Linux) for 8 AM daily. Pipe the output somewhere you'll actually read — your favorite channel (Telegram bot, email, Slack webhook). Now you have fleet-level monitoring.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.