How to Easily Monitor your Website Uptime for Free
July 16, 2007 – 1:48 pmCurrently, there are a bunch of website monitors available, some are free, but I couldn’t find any that was really simple and satisfy our requirements. We wanted a monitor that would connect to our site ThemBid.com every minute, retrieve a pixel image, and notify us if it retrieved something else or if it couldn’t be retrieved. As a result we wrote this simple monitor. If you want to use it, you need to have access to a server that has a task scheduler such as Cron and PHP support. Most shared hosting packages have this.
The reasoning behind it is simple: if we cannot retrieve our image but we can contact a reliable website such as Google, then send out a notification. To verify that we are retrieving an the correct image, we encode the image we retrieved with the following command:
# php -r 'echo "Encoded file: " . base64_encode(file_get_contents("http://www.thembid.com/images/dot.gif"))."\n";'
Encoded file: R0lGODlhAQABAIAAALu7uwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==
Once you have that string you are ready to change the configuration parameters for the monitor script. Save the code to a file called server_monitor.php and add the following to Cron to check your host every 5 minutes:
*/5 * * * * /path/to/server_monitor.php > /dev/null 2>&1
The following is what you should put on server_monitor.php
\r\n",
'-f' . NOTIFICATION_EMAIL);
}
?>
5 Responses to “How to Easily Monitor your Website Uptime for Free”
Excuse me, but are you running both your web site and your web site monitoring script ON THE SAME WEB SERVER?
If that’s what you’re doing, then isn’t your site-monitoring script ALWAYS going to be able to get your encoded image, even if your web site is no longer accessible on the web, due to a bad router or other network problem?
If you’re running your monitoring script from a different server, then that pretty much doubles the cost of running your web site, doesn’t it?
By Al Nonymous on Jul 18, 2007
No, running the script on the same server defeats the purpose. Thats a good point you make, but you can run this script on shared web hosting account or your computer at home.
By isaldana on Jul 18, 2007
Why waste bandwidth with an image? Why not just output 1 or OK and test for that?
By Name Required on Jul 18, 2007
That can be done too, we just use that image already.
By isaldana on Jul 18, 2007
I have a similar monitoring sript, but instead of retrieving an image it retrieves “OK”, which is only displayed, if a successful mysql query run. This way it not only checks for Apache availablity, but also for PHP and MySQL problems. (This indeed helped to notice some mysql problems.)
By Yaig on Jul 28, 2007