If you run a web site or blog of any importance to you or your business, it’s important to have a monitoring service to ensure that it’s always running, especially if you have a sophisticated service running background tasks. A good monitoring service can help you relax knowing that your site is operating well – unless you hear otherwise.

One paid monitoring service is ScoutApp, but it costs about $180 annually for a plan that includes SMS notifications. There’s also free, open source Nagios but that may be more complexity than you’ll need. Ironically, when I tried to reach their website last week – it was down.

This is exactly why I’m writing this tutorial; to prevent this on my site – and yours. Don’t you want to be the first one to know when your WordPress blog says: “Error establishing database connection”?

MonitorApp is a free, open source monitoring applet powered by the Yii Framework (it can be installed on any PHP/MySQL capable server) which sends notifications via email and/or to a smartphone application called Pushover ($4.99 in the iOS App Store, also available for Android). It’s a simple, economical way to monitor your services via smartphone.

MonitorApp ensures that your website is up, that your database is connected, that your disk isn’t full and that your background tasks are running successfully. If something goes wrong, it sends a notification to Pushover on your phone. When nothing’s wrong, it sends you a heartbeat notification every four hours so that you know your monitoring is running. MonitorApp can even monitor web pages for content changes. The source code is forkable on Github so you can easily customize and extend it to your needs.

Installing MonitorApp on Your Server

First, you’ll need to install the source code from Github. It’s best practice to run this applet on a different server than the sites that you are monitoring.

Follow the installation steps in the docs folder which are tested for the Rackspace Cloud with Ubuntu 12.04 but should work with any version of LAMP.

You can either clone the repository or download a copy. Configure the Apache site (as described in the installation steps) and restart Apache.

You’ll need to customize the /docs/monitorapp-config.ini file with your own settings, especially the MySQL access settings:

mkdir /var/www/secure cd /var/www/secure cp /var/www/monitorapp/docs/sample-config.ini /var/www/secure/monitorapp-config.ini sudo nano monitorapp-config.ini

Then, run the database migration to initialize MonitorApp. Database migrations are part of the Yii Framework, and serve to create tables and schema in a programmatic way:

cd /var/www/monitorapp ./app/protected/yiic migrate up

When prompted, enter a user name, email and password for your administrator account. This is what you’ll use to login in to MonitorApp’s home page.

You’ll also need to configure cron to run your content and service checks in the background every ten minutes. Edit your crontab file:

sudo crontab -e

Add the following line:

*/10 * * * * wget -O /dev/null http://monitorapp.yourdomain.com/cron/index

Getting Started with Pushover

To use MonitorApp, you’ll need to purchase and setup the Pushover application ($4.99).

You’ll need to register your MonitorApp application with Pushover and place its token in your config-monitorapp.ini file:

pushover_key = "your-app-token-here"

Make note of the separate device token and name assigned when you install the Pushover application on your smartphone. You’ll need to provide this information to MonitorApp’s web interface – the devices menu (see below).

Once you have installed Pushover on your smartphone, you can send test notifications from its web site.

The fun is just beginning.

One cool feature about Pushover is that you can program in quiet hours – so that you don’t have to receive notifications while you’re sleeping (but really, is that the kind of SysAdmin you want to be?).

Getting Started with MonitorApp

Once you’ve installed MonitorApp, you should be able to visit your home page at http://monitorapp.yourdomain.com and login with the credentials you created during the database migration.

Then, MonitorApp will require you add at least one device setting for your Pushover account.

Now you can begin adding your content and service checks. I’ve set up several for my startup, Geogram, which relies heavily on background tasks for managing email groups.

The screenshot below shows the various kinds of monitoring you can perform:

1) Check that a page contains certain content. Below, I’m checking that Geogram.com’s home page includes expected content. If this test fails, the home page is down.

2) Check that MySQL is running and connected.

3) Check that there is sufficient disk space

4) Check that the background scripts are running regularly

5) Check that error messages do not appear on a page – such as Nagios’ “Response Error”

6) Notify me whenever content changes on a page. e.g. a comment added (hint: you can use this to monitor third party websites too such as when concert event listings are announced)

For the database, disk space and cron checks, I’ve installed tiny code segments at Geogram to work with MonitorApp. Samples of this code are available on Github here. They are basically short PHP segments which you can add to almost any application. e.g. The MySQL code looks something up in the database and spits out a page that says ‘ok’. The DiskSpace code spits out a page with the number of free bytes. The Cron check spits out a page with the timestamp from the conclusion of the last cron job.

Here’s what it looks like in MonitorApp when you add service checks. Pushover offers a variety of great sound effects and you can choose different sounds for different alerts:

[galleria transition=”fade” height=”450″ width=”600″ speed=”3000″ enable=”show_imagenav,pause_on_interaction”]

[image]http://cloud.jeffreifman.com/wp-content/uploads/2013/08/check-home.png[/image]

[image]http://cloud.jeffreifman.com/wp-content/uploads/2013/08/check-mysql.png[/image]

[image]http://cloud.jeffreifman.com/wp-content/uploads/2013/08/on-changes.png[/image]

[/galleria]

You can run individual tests from the web interface – or test all the services at once as the cron background task will do:

You can test sending heartbeat notifications from MonitorApp’s menus. You can change the number of hours between heartbeat notifications in the config-monitorapp.ini file. You can also add multiple devices and alert different devices based on different service checks – or alert all of them. Go have some fun with it!

Learning More

I hope you’ve found this helpful. Please feel free to post corrections, questions or comments to this tutorial below. You can also reach me on Twitter @reifman or email me directly.

Please feel free to share this tutorial with others on Twitter and elsewhere.

(Note: I have no affiliate with Pushover or ScoutApp – although I will receive small commissions for Pushover sales through iTunes).