Your server went down and you heard it from your clients: simple monitoring in 15 minutes
The worst way to learn that your site is down is a client writing "something won't open". Usually the server stopped hours earlier: the disk filled up, memory ran out, or the machine simply rebooted and the service didn't start. The good news: you don't need an expensive system to be the first to know. Three checks and a notification on your phone are enough.
What to watch
- Is it alive: does the site open, does SSH answer. This is checked from outside, because a server that is down cannot report that it is down.
- Disk: a full disk is the number one cause of "mysterious" crashes. The database stops writing, logs stop, the site returns error 500.
- RAM: when memory runs out, Linux kills the biggest process. Usually that is MySQL/MariaDB, and the site is left without a database.
Check from outside (5 minutes)
Sign up for a free uptime checking service such as UptimeRobot and add:
- an HTTP(s) monitor for your site's address, if you have a site;
- a Port monitor for the server's SSH port, if you don't.
Disk and RAM with a small script (10 minutes)
The outside check can't see the disk or memory. For those, a script run from cron is enough. It sends a notification to your phone through ntfy, a free app for Android and iOS. Sending a notification is a single curl command, with no sign-up.1. Install the ntfy app and subscribe to a topic with a long random name, for example
my-server-k7q2x9. Anyone who knows the name can read the notifications, so never put passwords in them.2. Create the script:
Code: Select all
sudo nano /usr/local/bin/check-server.shCode: Select all
#!/bin/sh
TOPIC=my-server-k7q2x9
DISK_LIMIT=90
RAM_MIN_MB=200
# disk: every filesystem above the limit
df -P -x tmpfs -x devtmpfs | awk -v l=$DISK_LIMIT 'NR>1 {sub("%","",$5); if ($5+0 >= l) print $6, $5"%"}' |
while read fs pct; do
curl -s -d "$(hostname): disk $fs is $pct full" https://ntfy.sh/$TOPIC >/dev/null
done
# RAM: how many MB are really available
free_mb=$(free -m | awk '/^Mem:/ {print $7}')
if [ "$free_mb" -lt "$RAM_MIN_MB" ]; then
curl -s -d "$(hostname): only $free_mb MB RAM available" https://ntfy.sh/$TOPIC >/dev/null
fiCode: Select all
sudo chmod +x /usr/local/bin/check-server.sh
sudo /usr/local/bin/check-server.sh
echo '*/10 * * * * root /usr/local/bin/check-server.sh' | sudo tee /etc/cron.d/check-serverDISK_LIMIT=90 to 1, run the script, then change it back.
The server already went down. How to find out why
- When it rebooted:
last -x reboot | head - Errors from the previous boot:
journalctl -b -1 -p err - Did memory run out:
journalctl -k | grep -i "out of memory" - What fills the disk:
sudo du -xh / --max-depth=2 | sort -h | tail -15
journalctl -b -1 says there is no previous boot, logs are not kept across reboots. Fix it like this:
Code: Select all
sudo mkdir -p /var/log/journal
sudo systemctl restart systemd-journald
With us: the free Monitoring add-on
When you order a VPS from us, you can turn on the free Monitoring add-on. Every 5 minutes we check from outside that your server is running, that it answers on SSH (or RDP on Windows) and that the disk is not above 90 %. If there is a problem you get an email, and a second one when it is fixed. Nothing is installed on your machine. It works on all plans, including Windows.How do you find out that your server has a problem? Post here in the topic