monitoring your mongrel_rails with monit

27 01 2009

Monit is a very useful tool for systems administration. It monitors processes (among other things) so that you don’t have to. If something goes wrong with your processes (or files), it can try to restart them or alert you. Either way, it helps a lot when you have unstable processes due to performance issues (which is my problem right now)

Steps to monitor mongrel_rails in any environment, using monit (http://mmonit.com/monit/)

1. Monit must be installed in the server

Preferred version:
This is monit version 5.0_beta6
Copyright© 2008 by Tildeslash Ltd. All Rights Reserved.

Note: If not installed, download and install it.

2. Monit must have a configuration file in /etc/monitrc (or in other pre-specified places)

Sample monitrc:

set daemon 120 with start delay 60
set mailserver localhost

set mail-format {

from: sysadmin@aycron.com

subject: [aycron-server] $SERVICE $EVENT at $DATE

}
set alert etagwerker@aycron.com
set init
set logfile /var/log/monit

set httpd port 2812 and

use address localhost # only accept connection from localhost

allow localhost # allow localhost to connect to the server

##### mongrel 4010 #####

check process mongrel-4010 with pidfile /mnt/myapp.com/current/tmp/pids/mongrel.4010.pid

start program = ”/usr/bin/mongrel_rails cluster::start -C /mnt/myapp.com/shared/config/myapp.com.yml—clean—only 4010”

stop program = ”/usr/bin/ruby /usr/bin/mongrel_rails stop -P /mnt/myapp.com/current/tmp/pids/mongrel.4010.pid”

if totalmem is greater than 200.0 MB for 5 cycles then restart # eating up memory?

if cpu is greater than 50% for 2 cycles then alert # send an email to admin

if cpu is greater than 80% for 3 cycles then restart # hung process?

if loadavg(5min) greater than 10 for 8 cycles then restart # bad, bad, bad

#if 3 restarts within 5 cycles then timeout # something is wrong, call the sys-admin
if failed port 4010 protocol http # check for response
with timeout 120 seconds
then restart #it could also be then alert
group myapp_mongrels
##### mongrel 4011 #####
##### etc
##### …

Note: If it doesn’t exist, create it and define it for each mongrel_rails you want to follow.

3. Monit daemon must be running

To start it:

sudo monit -c /etc/monitrc &

Note: This will not start the processes defined in your /etc/monitrc – You could add it to inittab (in case system needs to reboot)

4. Fire up your processes (using the group name you defined in your /etc/monitrc)

sudo monit -g myapp_mongrels start all

You should see something like this:

Cleartext credentials needed for basic authorization!
start service ‘mongrel-4010’ on user request
monit daemon at 21065 awakened
Awakened by User defined signal 1
‘ip-10-251-214-192’ Monit has not changed
‘mongrel-4010’ start: /usr/bin/mongrel_rails
Cleartext credentials needed for basic authorization!
start service ‘mongrel-4011’ on user request
monit daemon at 21065 awakened
Cleartext credentials needed for basic authorization!
start service ‘mongrel-4012’ on user request
monit daemon at 21065 awakened
Cleartext credentials needed for basic authorization!
start service ‘mongrel-4013’ on user request
monit daemon at 21065 awakened
Cleartext credentials needed for basic authorization!
start service ‘mongrel-5010’ on user request
monit daemon at 21065 awakened
missing process: removing tmp/pids/mongrel.4010.pid
starting port 4010
‘mongrel-4010’ start action done
‘mongrel-4010’ start action done
‘mongrel-4011’ start: /usr/bin/mongrel_rails
starting port 4011
‘mongrel-4011’ start action done
‘mongrel-4011’ start action done
‘mongrel-4012’ start: /usr/bin/mongrel_rails
starting port 4012
‘mongrel-4012’ start action done
‘mongrel-4012’ start action done
‘mongrel-4013’ start: /usr/bin/mongrel_rails
starting port 4013
‘mongrel-4013’ start action done
‘mongrel-4013’ start action done
‘mongrel-5010’ start: /usr/bin/mongrel_rails
starting port 5010
‘mongrel-5010’ start action done
‘mongrel-5010’ start action done
Awakened by User defined signal 1

Note #1: You could add this command (or a restart command) to your cap file.

Note #2: To get rid of ‘Cleartext credentials needed for basic authorization!’, you will need to add something like this ‘allow username:password’ right below ‘allow localhost’ (or some other authentication method, more sophisticated approaches can be found in the monit manual)

5. You’re done!

If everything worked out correctly, you should receive a bunch of notifications in the mail box you defined in /etc/monitrc

Note: To test it, you could “kill -9” one of the mongrel_rails you’re ‘moniting’

There are better ways to define monitoring, but this will definitely be useful if you have nothing monitoring your production processes/mongrels. You can find more information about monit here: http://mmonit.com/monit/documentation/monit.html – Have fun! 



Mac OS X 10.4 + Rails console + readline problem

19 01 2009

Today I ran into this problem when trying to use my rails or ruby consoles:

[etagwerker@benteveo photos]$ irb
dyld: NSLinkModule() error
dyld: Symbol not found: _rl_filename_completion_function
Referenced from: /usr/local/lib/ruby/1.8/i686-darwin8.11.1/readline.bundle

Somehow I thought I had solved this problem months ago, but it came back! (Or maybe I had never solved it for real). Today, I noticed this problem when trying to run the ruby or rails console. AKA, irb and script/console respectively.

So, after a few cups of coffee and googling for almost two hours for the following terms:

  • “dyld: Symbol not found: _rl_filename_completion_function”
  • Mac OS X 10.4
  • Rails console
  • Ruby console (irb)
  • readline, readline.bundle

I finally found a solution for the problem. Hopefully, this time it won’t come back. Although no one knows (I’m an expert in messing up environments! And these days I’m maintaining code that uses different ruby/rails versions.. Ughh..)

I tried to follow Dan Benjamin’s advice (http://danbenjamin.com/articles/2005/12/ruby_rails_lighttpd_mysql_tiger) but that didn’t help. BTW, it is a great tutorial. Somehow it wasn’t solving my problem.

I tried to follow the suggestions mentioned in this thread (http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/5118) and that did it.

To sum things up, this is what I did:

  1. Searched in my mac OS X for readline.bundle
  2. Luckily, I found it
  3. cd readline
  4. ruby extconf.rb
  5. rm *.0 *.bundle
  6. sudo make install

To check that it was actually solved:

  1. irb
  2. script/console (on my rails project)

Problem solved!



cross browser compatibilities: theory vs. practice

16 01 2009

One would imagine that Firefox 3.0.5 would act the same in both Windows and Mac OS X. Well, in theory they should, right? At least, in my head, I think they should. After all, the same browser in different operating systems should render HTML in the same way. One would expect that. But that’s only theory. In practice, that doesn’t happen all the time.

I admit it, it happens 99% of the time. 99% comes directly from my gut and from my experience. We haven’t done a special study in Aycron about it. But that’s my feeling. As far as I know, I’ve seen this problem twice in the last three months. And we’ve written a lot of HTML/CSS in that time. That is not very often. But it still happens. That 1% of the times is very annoying because it takes a lot of time to come up with a workaround that works in every possible combination of FF, IE6, IE7, Safari and Windows, Mac OS X.

So, in theory, FF 3.0.5 should do the same in Windows or Mac OS X. In practice, it doesn’t. However, the percentage of times is very low. But the problem is still there. Believe me, I have triple (if not more) checked and there is a problem between FF for Windows and FF for Mac OS X, which is another headache for all of us developing sites for FF, IE6, IE7 and Safari.