Tim Igoe's Web Design, Development and Hosting Blog

Thursday July 29th

Monit Rules

As a follow on from my post on Monit, I have compiled a selection of rules that can be used to monitor various services on your server.

ssh.conf


 check process sshd with pidfile /var/run/sshd.pid
   start program  "/etc/init.d/sshd start"
   stop program  "/etc/init.d/sshd stop"
   if failed port 22 protocol ssh for 3 cycles then restart
   if 5 restarts within 5 cycles then timeout


postfix.conf


 check process postfix with pidfile /var/spool/postfix/pid/master.pid
   start program = "/etc/init.d/postfix start"
   stop  program = "/etc/init.d/postfix stop"
   if failed port 25 protocol smtp for 3 cycles then restart
   if 5 restarts within 5 cycles then timeout


mysql.conf


check process mysql with pidfile /var/run/mysqld/mysqld.pid
   group database
   start program = "/etc/init.d/mysqld start"
   stop program = "/etc/init.d/mysqld stop"
   if failed unixsocket /var/lib/mysql/mysql.sock protocol mysql for 3 cycles then restart
   if 5 restarts within 5 cycles then timeout


rootfs.conf


check filesystem rootfs with path /
 if space usage > 905 times within 15 cycles
   then alert


cpuusage.conf


check system localhost
if loadavg (1min) > 10 then alert
if loadavg (5min) > 7 then alert
if memory usage > 95% then alert
if cpu usage (user) > 95% then alert
if cpu usage (system) > 70% then alert
if cpu usage (wait) > 80% then alert

Friday July 23rd

PHP 5.2 Support Ends just as developers start to adopt it

With the recent release of PHP 5.2.14 the PHP Team has decided to end active support for this branch of PHP. This means there will be no further active development or bug fixes to this branch of PHP. Instead focus will be on PHP 5.3 and then onto PHP 6.

With many large projects still actively supporting PHP4, the choice is puzzling. A lot of web hosts still haven't upgraded from PHP 4 based servers due to various incompatibility issues, it can sometimes take weeks or months to test and check all code against the latest versions of PHP when they are released which does hold up rolling out upgrades to live servers, however problems like this shouldn't hold up the development of PHP.

From the PHP team's point of view, they can only support a version for a set period of time before it becomes too hard to keep back porting changes to the older releases. PHP 5.2 was released way back  in 2006, a lot has changed since then so it isn't unexpected to retire it now.

If a large package that is commonly used has issues on a certain version of PHP, it will hold back providers from upgrading to that version even if the benefits are there, this is especially true for shared hosting providers who tend to stick with the version that causes them the least problems and support.

There needs to be some changes somewhere to make the constant evolving nature of PHP easier to adopt and web site framework developers really need to evolve with PHP to help speed up the adoption of newer versions on a larger scale than they are (I'm thinking shared hosting providers here).

Wednesday July 21st

Monit - Keeping Servers running even while asleep

One of the downsides to working on the internet, is that it never stops - it is a 24 hour a day, 365 day a year system. There is not 'break' in it, no time to rest.

When you run your own websites this can be a problem, a lot of people however get website hosting from a company as part of a package where they manage and monitor the servers for you.

If, like me, you run your own server, a dedicated monitoring service often costs extra to the hosting package. Now, some of us like our sleep, but also like to know our services are
reliable, short of having someone awake 24 hours a day to monitor the servers you have to take chance that they will be reliable when you are away from an internet connected computer.

This is where monit comes in, it is a very useful package to allow a server to monitor itself for possible problems and restart / reset services if they start to run out of control.

Once installed, configuring monit is really straight forwards. Simply edit /etc/monit.conf and set up a few options pertaining to your server setup like mail server, and then how often you want to check services.

Once monit is configured, it is a case of setting up a collection of rules to tell monit how and what to scan.

httpd.conf


check process httpd with pidfile /var/run/httpd.pid
   group httpd
   start program = "/etc/init.d/httpd start" with timeout 60 seconds
   stop program  = "/etc/init.d/httpd stop"
   if cpu > 60% for 2 cycles then alert
   if cpu > 80% for 5 cycles then restart
   if failed host 127.0.0.1 port 80 protocol http for 5 cycles then restart
   if 5 restarts within 5 cycles then timeout


In this example, I'm monitoring Apache via process ID, we tell monit how to start and stop apache then set a few rules on how to deal with it. In this case, if the Apache starts to eat more than 60% of my CPU for 2 runs through I send an alert email, if it stays above 80% for 5 runs then I restart it. If a connection test fails, restart too.

This allows me to make sure my server always responds and if it does get too heavily loaded then reset itself to reign the load in.

Using Monit allows me to spend time away from my servers without worrying that excess load or a software crash can take them down for too long. This doesn't fix actual machine issues, but I just have to take the chance there.