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 4.01 Strict compliant 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:
- Visit the URL of the script. You can then download it in your browser:
- If you download the file by visiting the URL, you still must upload the file via FTP.
- If you’re able to SSH into your VPS, you can simply run:
[server]$ curl -s -o status.rb https://cdn.rawgit.com/watsonian/server-status-report/master/status.rb
The script is named status.rb, and the script itself is written in Ruby to take advantage of the ERB templating system to produce the HTML content.
Confirming if mailx is installed
Once you've downloaded the script successfully, you must make sure that the mailx package is installed on your PS.
To find out, run this command:
[server]$ dpkg -l | grep mailx
If you see output something like this:
ii bsd-mailx 8.1.2-0.20100314cvs-1 simple mail user agent
then that means it's installed.
If instead you see output like this:
rc mailx 8.1.2-0.20050715cvs-1 A simple mail user agent
then that means you need to install it.
You can only install mailx on a Dedicated server with an admin user. This is because it requires sudo. 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" "email@example.com"
If the above command does not work, try modifying '/user/bin/ruby' with '/user/bin/ruby1.8'.
- You can change the subject to anything you like.
- You can also change the email to any address you’d like the cron email sent to.
- 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.
- Running it once per hour is probably not a bad idea, but you can run it as frequently or infrequently as you like.
If you set everything up properly, then you should start getting emails that look roughly like this:
Keep in mind that this script is likely to update as time progresses if things change with server configurations. So, if this stops working on your server, be sure to check back to see if the script has updated. This was tested with the new SSD VPS on Ubuntu 12.04 LTS and so far there are no problems.