Set up a server status script on a VPS or Dedicated server

Overview

If you have a VPS or Dedicated Server, you might be interested in finding the status of that server without having to wait at a terminal window. Instead, you can run a script that emails you this information about the status of your server.

It works by outputing HTML content containing information on your server, including:

  • load average
  • memory usage
  • open network connections
  • top 10 memory processes
  • top 10 CPU processes
  • netstat output
  • top snapshot of all running processes

This only applies to your web server. Shell access to MySQL VPS is not available.

Installing a server script

Download a copy of the script in one of two ways.

It's recommended you add the script into your user's home directory.

FTP

Click the following link to download the script to your computer:

You must then upload the file via FTP.

SSH

Log in to your server via SSH. You can then simply run the following command to download the script:
[server]$ curl -s -o status.rb https://cdn.jsdelivr.net/gh/watsonian/server-status-report@master/status.rb

Confirming if mailx is installed

Once you've downloaded the script successfully, you must make sure that the mailx package is installed. To find out, run the following command:

[server]$ dpkg -l | grep mailx

If installed, you'll see the following output.

ii  bsd-mailx     8.1.2-0.20180807cvs-1     simple mail user agent

If instead, you see the following output, you need to install it.

rc  mailx     8.1.2-0.20050715cvs-1     A simple mail user agent

admin user. This is because it requires. Once logged in, run the following command:

[server]$ sudo apt-get install mailx

Creating a cron job

View the Crontab article for details on how to create a cron job under your shell user. Enter the following command in the panel when creating the cron job:

[server]$ /usr/bin/ruby /path/to/script/status.rb | /usr/bin/mail -a "Content-type: text/html;" -s "Status Report: $HOSTNAME" "some@example.com"
  • If you added the script to your user's home directory, you can change the path to ~/status.rb.
  • Change the email address to where you’d like the cron job email sent to.
  • You can change the subject to anything you like.
  • If you want to CC the email to more email addresses, you can use the -c flag and pass it a comma separated list of email addresses.

Email

If you set everything up properly, then you should start getting emails that look roughly like this:

Server status script preview.png

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?