I’ve been hanging around with a lot of mobile application developers lately, and so I’ve been thinking about the value folks get from services being available all the time. And, over the years, I’ve been asked many times how to get a page or an email sent to a cell phone when something happens on a server (where “something” can be “the web server crashed”, “disk space is running low”, “I got an email from my boss”, or “we just started getting referals from reddit.com in the access_log”).
The great thing about this question, unlike some questions (like “how do I migrate my application to a new server with zero downtime”), is that I already have a good answer and it’s pretty simple to explain (the “how do I migrate” question also has a good answer, but it’s not simple to explain, even if you’re using Virtualmin and everything can be bundled into a Virtualmin virtual server backup). The simple answer, in it’s shortest form, is “Use Webmin’s System and Server Status module.”
But, people never seem to believe that Webmin has a lock on best of breed solutions to so many problems…so they’ve been trying to use a bunch of standalone status and monitoring tools and gotten frustrated by how difficult they are to install, configure, or customize. While there are standalone products out there, and some of them are even pretty good, the Webmin option is dead simple to install, crazy simple to configure, and does probably all you’ll ever need.
So, install Webmin, if you don’t already have it on all of your servers. Go ahead and do that now. I’ll wait. If you have Virtualmin Professional, you can skip this step. It includes all of Webmin (hiding under the “Webmin” tab in the left menu).
Ok, so you’ve got it on all of your servers now, right? Wrong? Seriously, go ahead, install it on all of them. You don’t need to “try it” on one. You’re gonna love it and it’s free, and it gets more powerful the more servers you run it on. We’ll get to the “more servers, more power” thing in another post.
Now, login to Webmin (port 10000 in your web browser…something like http://mydomain.tld:10000, or https://mydomain.tld:10000, if you have the Perl Net:SSLeay module) and head on over the Others category. Click on “System and Server Status module.
There’s a bunch of monitors already setup, by default:

Yours will look different depending on the theme you’re using. All of the existing monitors are popular services type status monitors–the green check means the test resulted in a “true” result (which, depending on the test could be all kinds of things..in this screenshot, they’re mostly “is this service running?”). The red X means the test returned “false”, and the red box with an arrow pointing up means the test is “not available” (which could occur if the service is not even installed, or Webmin doesn’t know where to find the configuration and PID for the service).
Creating service status monitors is so easy, I think we’ll skip right ahead to something interesting. reddit is the coolest user-generated news site around, so if you starting finding reddit in the referer string on your server, your business might be picking up (and who knows, maybe the media will start calling to find out all about your new Web 2.0 AJAX-enabled frobnoxilator). So let’s setup a monitor to let us know about it the moment it happens.
So select “Execute Command” from the dropdown list. Enter a description (this will be in the title of all status reports via email). I called this monitor “Reddited!” to convey the necessary excitement. In the check on schedule field, select “Yes, and report on status changes”, so it’ll tell us when we start getting links from Reddit and after that we’ll only hear about it when we go a whole day without getting linked from Reddit. Finally, in the “Command to check exit status of” field, enter something like:
grep reddit /var/log/httpd/access_log
Where the log path should be replaced with the correct path to the relevant Apache access_log.
Save it. Now, unless you’re already getting hits from Reddit, you should see a little red X beside the Reddited entry. Now, get back to work to do something or write something cool enough to get your site on Reddit, so you can turn it into a green check!
Ok, now that you’ve done something cool to test your Reddited! status check, let’s set it up to send you a message. Click on the “Scheduled Monitoring” button. Set “Scheduled checking enabled?” to yes. Decide whether the default “Check every” periodicity is frequent enough for you (five minutes is the default, and that makes me happy, but maybe you wanna know within two minutes). Set the “Email status report to” to your email address, preferably the one on your phone so you’ll always be on top of things, even when skiing in the Swiss Alps with a couple of beautiful blond Scandinavians. Save it.
It can also use a pager to notify you of changes, if that’s the sort of thing you enjoy…but everybody these days has email-enabled phones, so let’s stick with the high tech route.
All done! Now have a look through the rest of the types of monitors that can be setup–there’s dozens of them. And if there isn’t already a perfect match, you can do what we’ve done here, and write your own command to do the job. Just write it such that it returns true when things are going right, so you get a green check when good things happen. This could also be used to call an arbitrarily complex shell script, perl/python/php/ruby script, or any other command on the system. (Don’t forget that grep can return false except when something isn’t found by adding “-v” to the command line.)
For more on this module, see the brief coverage in chapter 15 of the Book of Webmin (my book), and the much more comprehensive chapter 28 of Managing Linux Systems with Webmin (Jamie’s book). The latter is available in PDF format only at this time.
Edit (March 13): Webmin 1.332 and above has added an “email address” converter for folks who don’t know their mobile SMS email address. It knows about most of the major providers, so you just punch in your phone number and select the provider, and Webmin will be able to send you instant messages.