PS Server Status Script
If you have a Private Server, oftentimes you'll be interested in the status of that server without having to actually sit there staring at a terminal window. Wouldn't it be nice if you could run a script to email you information about the state of your PS? Well, that's exactly what this script does. It outputs 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
To install this script on your PS, the first thing you want to do is download a copy of the script to use. To do that, SSH to your PS under the user you want to run the script as and run this command:
curl -s -o status.rb https://cdn.rawgit.com/watsonian/server-status-report/master/status.rb
That will save the script as a file named status.rb. The script itself is written in Ruby to take advantage of the ERB templating system to produce the HTML content.
Once you've downloaded the script successfully, you need to make sure that the mailx package is installed on your PS. To find out, run this command:
dpkg -l | grep mailx
If you see output like this:
ii mailx 8.1.2-0.20050715cvs-1 A 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. To do so, login with an admin user you created (if you haven't created one yet, go to the Manage Admin Users area of your webpanel to create one) and run the following command:
sudo apt-get install mailx
Now you're ready to create a cron job to send yourself your status report. Go to the Cron Jobs area of your webpanel and create a new cron job that runs as the user your downloaded the script using. The command you want to run is as follows:
/usr/bin/ruby /path/to/script/status.rb | /usr/bin/mail -a "Content-type: text/html;" -s "Status Report: $HOSTNAME" "firstname.lastname@example.org"
You can change the subject to whatever you want and just replace email@example.com with the address you want the 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 the above command does not work, try modifying '/user/bin/ruby' to be '/user/bin/ruby1.8'.
If you set everything up properly, then you should start getting emails that look roughly like this:
Keep in mind that this script will likely be updated as time progresses if things change with PS configurations. So, if this stops working on your PS, be sure to check back to see if the script has been updated.