Jens Krämer

Keep an eye on your DRb server with Monit

 |  monit, server, ferret

Many people nowadays seem to use monit to ensure their Rails application is always up and running, and maybe even to get notified in case of any problems like unusual high load or memory usage.

Since acts_as_ferret doesn’t really like it when the DRb server has gone away, it’s a good idea to not only monitor your Mongrels, but also the DRb server itself. So here’s for you a small snippet of monit configuration derived from one I’m using elsewhere:

# monit configuration snippet to watch the Ferret DRb server shipped with

acts_as_ferret

check process ferret with pidfile /path/to/ferret.pid

# username is the user the drb server should be running as (It's good practice
# to run such services as a non-privileged user)
start program = "/bin/su -c 'cd /path/to/your/app/current/ && RAILS_ENV=production script/ferret_start' username"
stop program = "/bin/su -c 'cd /path/to/your/app/current/ && RAILS_ENV=production script/ferret_stop' username"

# cpu usage boundaries
if cpu > 60% for 2 cycles then alert
if cpu > 90% for 5 cycles then restart

# memory usage varies with index size and usage scenarios, so check how
# much memory your DRb server uses up usually and add some spare to that
# before enabling this rule:
# if totalmem > 50.0 MB for 5 cycles then restart

# adjust port numbers according to your setup:
if failed port 9010 then alert
if failed port 9010 for 2 cycles then restart
group ferret </code>

As you can see it’s pretty straightforward, well, maybe except the start/stop commands which took me a few iterations to get right. I also added this to the acts_as_ferret distribution: monit-example.