A VPS does not fail loudly. It degrades — a disk fills slowly, a certificate quietly expires on a Sunday, inodes creep toward the limit while the dashboard still shows plenty of free space. The only reliable defence is a set of health checks that run on a schedule and leave a trail you can read after the fact. This checklist is the set of checks worth automating on a typical 1–4 vCPU KVM guest running Debian or Ubuntu, plus the thresholds that make each check meaningful rather than noisy.
Start with the metrics that actually predict outages
Most monitoring tutorials start with CPU. That is the wrong first choice. CPU is rarely the thing that takes a small VPS down; disk space, inodes, memory pressure and certificate expiry are far more common culprits. Rank your checks by “how often has this actually caused an incident for me” and schedule accordingly: cheap, high-signal checks every minute; expensive checks hourly or daily.
| Check | Command | Warn | Critical | Interval |
|---|---|---|---|---|
| Disk space | df -h --output=pcent,target | 80% | 90% | 5 min |
| Inodes | df -i | 80% | 90% | 1 hour |
| Memory available | /proc/meminfo MemAvailable | <15% | <8% | 1 min |
| Swap in/out rate | vmstat 1 5 si/so | >0 sustained | >200 KB/s | 1 min |
| Certificate expiry | openssl s_client | 21 days | 7 days | 1 day |
| Backup freshness | mtime of latest archive | 26 h | 50 h | 1 hour |
| Service state | systemctl is-active | degraded | failed | 1 min |
Filesystem checks: space is only half the story
A full disk is obvious. A disk that is 45% used with 100% of inodes consumed is not — and it will make apt, PHP session writes and log rotation fail in ways that look like application bugs. Check both, and check them per filesystem rather than in aggregate, because a small /var partition is the one that fills first:
df -h --output=source,fstype,pcent,target | awk 'NR==1 || $3+0 >= 80'
df -i --output=source,ipcent,target | awk 'NR==1 || $2+0 >= 80'
du -xhd1 /var | sort -rh | head -n 10
The -x flag on du matters: without it, a bind-mounted backup directory inside /var will be counted twice and send you hunting in the wrong place. If /var/log is your top consumer, the fix is usually journald rather than logrotate.
Cap journald before it eats the disk
Default journald behaviour on a small disk is unbounded growth capped only by a percentage of the filesystem. On a 40 GB volume that can be several gigabytes of logs nobody reads. Set a hard ceiling in /etc/systemd/journald.conf:
[Journal]
SystemMaxUse=500M
SystemMaxFileSize=50M
MaxRetentionSec=14day
Compress=yes
Then systemctl restart systemd-journald and confirm with journalctl --disk-usage. Keep MaxRetentionSec long enough that a problem that started on Friday is still visible on Monday — fourteen days is a reasonable compromise on a small guest.
Memory pressure: watch MemAvailable, not MemFree
Linux uses free RAM for page cache, so MemFree sitting near zero is normal and healthy. The number that matters is MemAvailable, the kernel’s own estimate of how much memory can be handed to a new workload without swapping. A flat one-liner that works on any modern kernel:
awk '/MemTotal|MemAvailable|SwapTotal|SwapFree/ {printf "%-14s %8.0f MB\n", $1, $2/1024}' /proc/meminfo
awk '/MemTotal/{t=$2} /MemAvailable/{a=$2} END{printf "available: %.1f%%\n", a/t*100}' /proc/meminfo
Two consecutive readings under 10% available, taken a minute apart, are worth alerting on. One reading is not — a backup tar running at that moment will produce a single low sample. Also log the swap-in/out columns from vmstat 1 5: sustained so above roughly 200 KB/s on a VPS with local SSD means you are memory-bound, and the fix is a bigger plan or a smaller working set, not a tuning flag.
Service liveness that catches the “running but broken” case
systemctl is-active tells you the unit has not crashed. It does not tell you the process is answering requests. Pair it with an application-level probe on localhost so the check exercises the real code path — database connection, PHP-FPM pool, upstream.
#!/bin/bash
# /usr/local/sbin/health.sh
fail=0
for u in nginx php8.2-fpm postgresql redis-server; do
systemctl is-active --quiet "$u" || { echo "DOWN: $u"; fail=1; }
done
curl -sS -m 5 -o /dev/null -w '%{http_code}' http://127.0.0.1/healthz \
| grep -qx 200 || { echo "HTTP probe failed"; fail=1; }
pg_isready -q -h 127.0.0.1 || { echo "postgres not accepting"; fail=1; }
exit $fail
Run it from a systemd timer every minute, logging the exit code into journald. Because the output goes to the journal, you get a free history of when a service was flapping, not just that it is down now.
Certificates and DNS: the silent expiry class
Let’s Encrypt renewals fail for boring reasons — an HTTP-01 challenge blocked by a redirect, a rate limit hit during a bulk reissue, or the ACME client’s timer disabled by an OS upgrade. Check the actual certificate the server presents, not the renewal config:
for d in example.com www.example.com; do
end=$(echo | openssl s_client -servername "$d" -connect "$d":443 2>/dev/null \
| openssl x509 -noout -enddate | cut -d= -f2)
days=$(( ( $(date -d "$end" +%s) - $(date +%s) ) / 86400 ))
printf "%-24s %3d days\n" "$d" "$days"
done
Alert at 21 days, page at 7. The 21-day warning leaves room to fix a broken challenge before the client’s own retry window closes. While you are at it, verify the DNS A record still points at the VPS — a migration that half-finished is a classic cause of “the site works for me” incidents.
Backups: verify, do not just schedule
An unverified backup is a rumour. Two checks make it real: the newest archive must be recent, and its size must be roughly what you expect. A backup job that silently exits after writing a 4 KB empty tarball passes a freshness check and fails you on restore day.
latest=$(ls -1t /var/backups/db/*.sql.zst 2>/dev/null | head -1)
[ -n "$latest" ] || { echo "no backup found"; exit 2; }
age=$(( ( $(date +%s) - $(stat -c %Y "$latest") ) / 3600 ))
size=$(stat -c %s "$latest")
echo "$latest age=${age}h size=$((size/1024/1024))MB"
[ "$age" -lt 26 ] || echo "WARN: backup older than 26h"
[ "$size" -gt 1048576 ] || echo "CRIT: suspiciously small archive"
Once a month, actually restore the newest archive into a scratch database and run a SELECT count(*) against your two biggest tables. That practice catches corrupted dumps, missing sequences and wrong-encoding problems that no size check will find.
Kernel and package drift
Automate the boring kind of patch management: security updates applied automatically, kernel packages installed but not rebooted silently for months. On Ubuntu, unattended-upgrades handles the first part; the second part needs a check against /var/run/reboot-required plus a comparison of running versus installed kernel.
[ -f /var/run/reboot-required ] && echo "reboot required: $(cat /var/run/reboot-required.pkgs | tr '\n' ' ')"
running=$(uname -r)
installed=$(dpkg-query -W -f='${Version}\n' "linux-image-$running" 2>/dev/null | cut -d- -f1)
echo "running=$running newest=$(ls -1t /boot/vmlinuz-* | head -1)"
If those two disagree for more than a week, schedule a reboot window. A kernel that is patched on disk but not in memory gives you a false sense of security, and livepatch covers only a subset of vulnerabilities. This is also the moment to check that the guest reboots cleanly — a VPS that comes back from a reboot with a failed fstab mount is a worse outage than the one you were patching.
Putting it on a timer and reviewing the trail
A single script on a systemd timer is easier to audit than a pile of cron entries spread across users. Keep one unit for the minute-level checks and one for the daily deep checks, and have both write structured lines you can grep later:
# /etc/systemd/system/health.service
[Unit]
Description=Host health checks
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/health.sh
# /etc/systemd/system/health.timer
[Unit]
Description=Run health checks every minute
[Timer]
OnBootSec=90s
OnUnitActiveSec=60s
AccuracySec=5s
[Install]
WantedBy=timers.target
Enable with systemctl enable --now health.timer and confirm the first run landed with journalctl -u health -n 20. Note OnBootSec=90s: running the check before networking is up will produce a cluster of false failures at every reboot, which is the fastest way to teach yourself to ignore alerts.
The last piece is a weekly five-minute review. Read the journal for the week, count how many alerts fired, and delete the ones that never produced action. A checklist that stays small enough to trust beats a full observability stack you never look at. If your guest is still running default tuning from the image, pair these checks with a pass over the kernel and service settings on VirtualServersVPS — health checks tell you something is wrong; sane defaults mean fewer things go wrong in the first place.




Leave a Reply
You must be logged in to post a comment.