AlphornAlphorn Docs

Server & Infrastructure Monitoring

Alert on disk space, CPU, memory, and other server metrics.

Lightweight server monitoring doesn't need a full observability stack. A few scripts and Alphorn can alert you before problems become outages.

Disk space alerts

check-disk.sh
#!/bin/bash
WEBHOOK="https://app.alphorn.dev/api/webhooks/wh_abc123"
THRESHOLD=85
HOSTNAME=$(hostname)

df -h --output=pcent,target | tail -n+2 | while read usage mount; do
  PERCENT=${usage%\%}
  if [ "$PERCENT" -ge "$THRESHOLD" ]; then
    curl -s -X POST "$WEBHOOK" \
      -H "Content-Type: application/json" \
      -d "{
        \"title\": \"Disk space warning: $HOSTNAME\",
        \"message\": \"$mount is at ${PERCENT}% capacity\",
        \"priority\": 4,
        \"tags\": [\"server\", \"disk\", \"$HOSTNAME\"]
      }"
  fi
done

Memory usage

check-memory.sh
#!/bin/bash
WEBHOOK="https://app.alphorn.dev/api/webhooks/wh_abc123"
THRESHOLD=90
HOSTNAME=$(hostname)

MEM_PERCENT=$(free | awk '/^Mem:/ {printf "%.0f", $3/$2 * 100}')

if [ "$MEM_PERCENT" -ge "$THRESHOLD" ]; then
  curl -s -X POST "$WEBHOOK" \
    -H "Content-Type: application/json" \
    -d "{
      \"title\": \"High memory usage: $HOSTNAME\",
      \"message\": \"Memory at ${MEM_PERCENT}%. Top processes:\n$(ps aux --sort=-%mem | head -6 | tail -5 | awk '{printf \"%s %s%%\\n\", $11, $4}')\",
      \"priority\": 4,
      \"tags\": [\"server\", \"memory\", \"$HOSTNAME\"]
    }"
fi

CPU load

check-cpu.sh
#!/bin/bash
WEBHOOK="https://app.alphorn.dev/api/webhooks/wh_abc123"
HOSTNAME=$(hostname)
CORES=$(nproc)
LOAD=$(awk '{print $1}' /proc/loadavg)

# Alert if 5-min load exceeds number of CPU cores
if [ "$(echo "$LOAD > $CORES" | bc)" -eq 1 ]; then
  curl -s -X POST "$WEBHOOK" \
    -H "Content-Type: application/json" \
    -d "{
      \"title\": \"High CPU load: $HOSTNAME\",
      \"message\": \"Load average: $LOAD (${CORES} cores)\",
      \"priority\": 4,
      \"tags\": [\"server\", \"cpu\", \"$HOSTNAME\"]
    }"
fi

SSL certificate expiry

check-ssl.sh
#!/bin/bash
WEBHOOK="https://app.alphorn.dev/api/webhooks/wh_abc123"
DOMAIN="your-app.com"
DAYS_WARNING=14

EXPIRY=$(echo | openssl s_client -servername "$DOMAIN" -connect "$DOMAIN:443" 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2)
EXPIRY_EPOCH=$(date -d "$EXPIRY" +%s)
NOW_EPOCH=$(date +%s)
DAYS_LEFT=$(( (EXPIRY_EPOCH - NOW_EPOCH) / 86400 ))

if [ "$DAYS_LEFT" -le "$DAYS_WARNING" ]; then
  curl -s -X POST "$WEBHOOK" \
    -H "Content-Type: application/json" \
    -d "{
      \"title\": \"SSL certificate expiring soon\",
      \"message\": \"$DOMAIN expires in $DAYS_LEFT days ($EXPIRY)\",
      \"priority\": 4,
      \"tags\": [\"server\", \"ssl\", \"$DOMAIN\"]
    }"
fi

Cron schedule

Run all checks periodically:

*/5 * * * * /path/to/check-disk.sh
*/5 * * * * /path/to/check-memory.sh
*/5 * * * * /path/to/check-cpu.sh
0 8 * * *   /path/to/check-ssl.sh

Routing examples

ChannelFilterPurpose
Slack (#infra)tags CONTAINS "server"All server alerts
PagerDutypriority >= 4 AND tags CONTAINS "server"Page on-call for critical issues
Emailtags CONTAINS "ssl"Track certificate status

On this page