What you'll get
By the end of this guide, your phone will buzz when:
- Your website goes down
- Disk space runs low
- Someone SSHs into your server
- A critical service crashes
No Prometheus. No Grafana. No Docker. Just bash, cron, and Nerve.
Step 1: Install Nerve CLI on your server
SSH into your server and run:
command -v go >/dev/null || {
GO_VERSION="$(curl -fsSL 'https://go.dev/VERSION?m=text' | head -n 1)"
case "$(uname -m)" in
x86_64|amd64) GO_ARCH="amd64" ;;
aarch64|arm64) GO_ARCH="arm64" ;;
esac
curl -fsSLO "https://go.dev/dl/${GO_VERSION}.linux-${GO_ARCH}.tar.gz"
sudo tar -C /usr/local -xzf "${GO_VERSION}.linux-${GO_ARCH}.tar.gz"
rm -f "${GO_VERSION}.linux-${GO_ARCH}.tar.gz"
echo 'export PATH="/usr/local/go/bin:$(go env GOPATH)/bin:$PATH"' >> ~/.bashrc
export PATH="/usr/local/go/bin:$PATH"
}
go install github.com/nerve-ink/nerve-cli/cmd/nerve@latest
Step 2: Set your DSN
Add your Nerve DSN to the server's environment so all scripts can use it:
echo 'export NERVE_DSN="nerve://TOKEN:[email protected]"' | sudo tee /etc/profile.d/nerve.sh
sudo chmod +x /etc/profile.d/nerve.sh
source /etc/profile.d/nerve.sh
Step 3: Create the all-in-one monitoring script
#!/bin/bash
# /usr/local/bin/nerve-server-check.sh
set -euo pipefail
export PATH="/usr/local/go/bin:$(go env GOPATH 2>/dev/null || echo /root/go)/bin:$PATH"
source /etc/profile.d/nerve.sh 2>/dev/null || true
HOST=$(hostname)
# --- Check 1: Website uptime ---
URL="https://yoursite.com"
HTTP=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$URL" || echo "000")
if [ "$HTTP" = "000" ] || [ "$HTTP" -ge 500 ]; then
echo "DOWN: $URL (HTTP $HTTP) on $HOST" | nerve send --severity critical
fi
# --- Check 2: Disk space (alert at 90%) ---
df -h --output=target,pcent -x tmpfs -x devtmpfs 2>/dev/null | tail -n +2 | while read -r mount pct; do
usage="${pct%%%}"
if [ "$usage" -ge 90 ]; then
echo "DISK: $mount is ${usage}% on $HOST" | nerve send --severity critical
fi
done
# --- Check 3: Failed systemd services ---
FAILED=$(systemctl list-units --state=failed --no-legend --plain 2>/dev/null | head -5)
if [ -n "$FAILED" ]; then
echo "FAILED SERVICES on $HOST: $FAILED" | nerve send --severity critical
fi
# --- Check 4: High memory usage (alert at 90%) ---
MEM_USED=$(free | awk '/^Mem:/ {printf "%.0f", $3/$2 * 100}')
if [ "$MEM_USED" -ge 90 ]; then
echo "MEMORY: ${MEM_USED}% used on $HOST" | nerve send --severity alert
fi
# --- Check 5: High load average ---
LOAD=$(awk '{print $1}' /proc/loadavg)
CPUS=$(nproc)
HIGH=$(echo "$LOAD > $CPUS * 2" | bc -l 2>/dev/null || echo "0")
if [ "$HIGH" = "1" ]; then
echo "LOAD: $LOAD (${CPUS} CPUs) on $HOST" | nerve send --severity alert
fi
sudo chmod +x /usr/local/bin/nerve-server-check.sh
Step 4: Add SSH login alerts
cat > /etc/profile.d/nerve-ssh-alert.sh << 'EOF'
if [ -n "$SSH_CLIENT" ]; then
IP=$(echo "$SSH_CLIENT" | awk '{print $1}')
echo "SSH: $USER@$(hostname) from $IP" \
| NERVE_DSN="$(cat /etc/profile.d/nerve.sh | grep NERVE_DSN | cut -d'"' -f2)" \
/usr/local/go/bin/nerve send 2>/dev/null &
fi
EOF
chmod +x /etc/profile.d/nerve-ssh-alert.sh
Step 5: Schedule it
# Run every 3 minutes
(crontab -l 2>/dev/null; echo "*/3 * * * * /usr/local/bin/nerve-server-check.sh") | crontab -
Test it
# Send a test signal
echo "test alert from $(hostname)" | nerve send
# You should get a push notification on your phone
What's next
You now have basic server monitoring. As your setup grows, add more checks: