Topic: HOWTO: Let GOD watch over your Mongrels!

Monitoring the mongrels in your rails app is important when your website is in production. Sometimes things can go wrong, and your mongrels can start chewing up increasing amounts of memory and cpu power that could bring your rails app to its knees. So, you need something to keep an eye on them and restart them when this happens. There are various solutions available to achieve this. The common options are Monit, Munin, or GOD:




Of the 3 above solutions, i have found GOD to be the easiest to set up. I will try and outline the steps i took to get things working. I will also show you how i integrate this with Google Apps Mail for email notifications. The details of how to manipulate the GOD configuration are explained in depth on the GOD website, so i will not discuss that here.

My production server is running the following:

    * Rails 2.0.2
    * Ubuntu Gutsy
    * nginx 0.5.26
    * mongrel 1.1.4
    * mongrel_cluster 1.0.5
    * god 0.7.8
    * tlsmail 0.0.1

Step 1:

Install the god gem:

sudo gem install god

Step 1a (OPTIONAL):

Install the tlsmail gem if you want to use GMail:

sudo gem install tlsmail

You can read more about using GMail in your rails app in my previous blog post: … l-smt.html

Step 2:

Find and edit the init.d script.

cd /etc/init.d
ls -l
sudo nano /etc/init.d./god

It should look like this:

Run these commands to make the god script executable and allow it to start on a reboot of the server.

chmod +x /etc/init.d/god
/usr/sbin/update-rc.d god defaults

Step 3:

Create your god config file.

cd /etc
sudo nano god.conf

This is basically a configuration taken from the god website, but i had to make some changes to the location of the pid files, make sure you get this right - otherwise things will not work the way they should (you can also exclude the code from line 60 onwards if you are not using email notifications with GMail):

Step 4:

Start god:

sudo /etc/init.d/god start

You should see something like this:

Sending 'load' command

The following tasks were affected:


Step 5:

Check whether your mongrels are being monitored:

sudo god status

You should see something like this:

mydomain-mongrel-8000: up
mydomain-mongrel-8001: up
mydomain-mongrel-8002: up

If god is not monitoring your mongrels, you will see this:

mydomain-mongrel-8000: unmonitored
mydomain-mongrel-8001: unmonitored
mydomain-mongrel-8002: unmonitored

Step 6:

Now, to really see god in action, i look at the log files:

sudo god log mydomain-mongrel-8000
sudo god log mydomain-mongrel-8001
sudo god log mydomain-mongrel-8002

You should start seeing messages like this, which means it is working:

INFO: mydomain-mongrel-8000 [ok] process is running (ProcessRunning)
INFO: mydomain-mongrel-8000 [ok] memory within bounds [59456kb, 59456kb, 59456kb, 59456kb, 59456kb] (MemoryUsage)
INFO: mydomain-mongrel-8000 [ok] cpu within bounds [0.00891569765038892%, 0.00891040849797263%, 0.00890512561731393%, 0.00889984899726403%, 0.00889457862670062%] (CpuUsage)

Step 7:

To stop god:

sudo /etc/init.d/god stop

Step 8:

Lastly, I recommend changing the memory or cpu useage to a lower level and then watching the logs to see that god is picking up on this and restarting the mongrels, as well as sending emails!


That's it, check out the GOD website and Google Group for more info!

Re: HOWTO: Let GOD watch over your Mongrels!

I like God, I love the way it works, but on my server it leaks, a lot. So people if you use it, keep an eye on it, and if it's leaking consider monit because as awesome as God is, the memory leaks (if present) kind of make that irrelevant. Keep an eye on it.