How to monitor server uptime from your SSH client

Uptime monitoring checks a server from outside at a fixed interval and alerts you when it stops answering. Check the SSH port (22) with a TCP check, your site with an HTTP check that looks for a word on the page, and the SSL certificate and domain for expiry. Check every 1 to 5 minutes, and alert only after two failed checks in a row, confirmed from a second location, so one lost packet does not wake you up.

Updated . The manual checks were run on macOS with nc, ping, curl 8.7 and OpenSSL 4.1 against public sites.

What to check

A server can be up and still fail the people who use it. Pick the check that matches what they need:

CheckCatches
TCP port, such as SSH on 22The server is off, sshd stopped, a firewall rule blocks the port
PingThe machine or its network is unreachable
Website (HTTP)Errors such as 502, slow pages, a page that loads but shows an error
SSL certificateA certificate that is invalid or expires in the next days
Domain expiryA domain that is about to lapse
HeartbeatA cron job or backup that did not run

A port check is the minimum for any server you reach over SSH. For a site, look for a word that only the working page contains: a page with an error message also answers 200.

Check it by hand first

These commands show what a monitor sees. Is the SSH port open?

nc -zv -w 5 server.example.com 22

succeeded means the port answers. A timeout points at the network or a firewall, a refusal at the service: see Connection timed out and Connection refused.

Does the site answer, and how fast?

curl -fsS -o /dev/null -w '%{http_code} %{time_total}\n' https://example.com/
curl -fsS https://example.com/ | grep -q 'Example Domain' && echo found

When does the certificate expire, and does it expire in the next 14 days?

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -enddate
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -checkend 1209600

And the domain:

whois example.com | grep -i 'expir'

Why the check has to run from outside

A script on the server cannot tell you the server is off, and it does not see a firewall, DNS or routing problem between it and your users. Run the checks from another network, at a fixed interval, and keep a record of each result.

One failed check proves little: a packet gets lost, a route flaps for a few seconds. Good monitoring waits for a few failures in a row and checks again from somewhere else before it alerts you.

Set it up in Wardterm

  1. In the server list, open the server's menu (right-click on a computer, long press on a phone or iPad) and choose Monitor this server. It checks the SSH port every 5 minutes and keeps the server's name, which only you see.
  2. For other checks, open Monitoring and choose Add monitor.
  3. Choose the Type: TCP port, Ping, Website (HTTP), SSL certificate, Domain expiry or Heartbeat (cron).
  4. Pick a server from your vault or type an address, then the Port if it asks: 22, 443, 3306 or another.
  5. Set Check every: 1, 5, 10, 15, 30 or 60 minutes.
  6. For a website, set the Expected status code, a time above which it counts as down, and a Text on the page that must or must not appear. For SSL and domains, set how many days before expiry you want the alert.
  7. Choose Test to check it once now, then save.

Test shows the result with its timings: DNS, connection, first byte, the status code, the certificate's issuer and days left. Test from a second country runs it from another network too.

Only public internet addresses can be checked: local network, VPN and private IPs cannot. For a private server, monitor what is public in front of it, such as the site or the bastion host.

Choose the interval

  • 1 minute for production servers and sites where every minute of downtime counts.
  • 5 minutes for most servers. It is what Monitor this server uses.
  • 60 minutes for SSL certificates and domains, which change slowly.

Alerts without false alarms

A monitor is down after 2 failed checks in a row, confirmed from a second country. Change both in the monitor: Alert after goes from 1 to 5 failed checks, and Confirm from a second country can be turned off.

You get one alert when it goes down and one when it is back, with how long it was down. In Alert settings choose push, email or both, a reminder while it is still down, and a daily or weekly uptime summary by email. Each monitor can also have its own alerts, or none.

Running a cron job or a backup? Use a heartbeat check. Want to show the status to your users? See how to create a status page.

Questions

What is server uptime monitoring?

A service checks your server from outside at a fixed interval, for example whether port 22 accepts a connection or a page loads, and alerts you when it fails and again when it is back.

How often should I check my server?

Every 1 to 5 minutes for servers and sites people use. SSL certificates and domains change slowly, so once an hour is enough for them.

Can I monitor a server on my local network or VPN?

Not from an outside service: it can only reach public internet addresses. Monitor the public part instead, such as the website, the jump host or the router's forwarded port.

How do I avoid false alarms?

Alert only after two or more failed checks in a row, and confirm the failure from a second location before alerting. A single timeout is usually the network, not the server.

Sources

All guides