Back To The Main Support Page

Monitoring Your App

Slingshot Hosting and Highgroove Studios know that keeping an eye on your Rails application is important.

That's why we built Heartbeat -- a simple, easy-to-use monitoring system that's requires no setup. We encourage you to sign up, even if you're not a customer of ours!

Heartbeat is a web interface for maintaining and monitoring your Ruby on Rails applications. With Heartbeat, you can monitor the uptime of URLs and run your application's rake tasks from a single web page. Heartbeat can be extended however you want - if you can write a rake task, Heartbeat can execute it!.

There are other ways to monitor an application, from the server itself. For this, we use monit.

Using monit to monitor your Rails application

"monit is a utility for managing and monitoring, processes, files, directories and devices on a UNIX system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations." -- monit homepage.

Slingshot servers come setup with monit. All you have to do is plug in the details.

First, configure monit.conf to your liking. Might we suggest changing/uncommenting:

set mailserver localhost
set alert youremail@yourdomain.com   # receive all alerts

  check system daytona.slingshothosting.com
    if loadavg (1min) > 4 then alert
    if loadavg (5min) > 2 then alert
    if memory usage > 75% then alert  # this one is debatable
    if cpu usage (user) > 70% then alert
    if cpu usage (system) > 30% then alert
    if cpu usage (wait) > 20% then alert

include /etc/monit.d/*

Now, create a file in /etc/monit.d/ called mongrel.conf (or name it after your application).

We're working on a way to automate the building of this file with our capistrano scripts, but for now you'll have to add it manually. It might look a little something like this:

# /usr/local/bin/ruby /usr/local/bin/mongrel_rails start -d -e production -p 8001 -a 127.0.0.1 -l /var/www/apps/yourapp/current/log/mongrel.log -P /var/www/apps/yourapp/shared/log/mongrel.8001.pid -c /var/www/apps/yourapp/current

check process mongrel-8000 with pidfile /var/www/apps/yourapp/current/log/mongrel.8000.pid
  group mongrel
  start program = /usr/local/bin/ruby /usr/local/bin/mongrel_rails start -d -e production -p 8000 -a 127.0.0.1 -l /var/www/apps/yourapp/current/log/mongrel.log -P /var/www/apps/yourapp/shared/log/mongrel.8000.pid -c /var/www/apps/yourapp/current
  stop program  = /usr/local/bin/ruby /usr/local/bin/mongrel_rails stop -P /var/www/apps/yourapp/shared/log/mongrel.8000.pid
  if totalmem > 100.0 MB for 5 cycles then restart
  if failed port 8000 protocol http with timeout 10 seconds then restart

check process mongrel-8001 with pidfile /var/www/apps/yourapp/current/log/mongrel.8001.pid
  group mongrel
  start program = /usr/local/bin/ruby /usr/local/bin/mongrel_rails start -d -e production -p 8001 -a 127.0.0.1 -l /var/www/apps/yourapp/current/log/mongrel.log -P /var/www/apps/yourapp/shared/log/mongrel.8001.pid -c /var/www/apps/yourapp/current
  stop program  = /usr/local/bin/ruby /usr/local/bin/mongrel_rails stop -P /var/www/apps/yourapp/shared/log/mongrel.8001.pid
  if totalmem > 100.0 MB for 5 cycles then restart
  if failed port 8001 protocol http with timeout 10 seconds then restart

check process mongrel-8002 with pidfile /var/www/apps/yourapp/current/log/mongrel.8002.pid
  group mongrel
  start program = /usr/local/bin/ruby /usr/local/bin/mongrel_rails start -d -e production -p 8002 -a 127.0.0.1 -l /var/www/apps/yourapp/current/log/mongrel.log -P /var/www/apps/yourapp/shared/log/mongrel.8002.pid -c /var/www/apps/yourapp/current
  stop program  = /usr/local/bin/ruby /usr/local/bin/mongrel_rails stop -P /var/www/apps/yourapp/shared/log/mongrel.8002.pid
  if totalmem > 100.0 MB for 5 cycles then restart
  if failed port 8002 protocol http with timeout 10 seconds then restart

Note: if you're using a different user (the deploy user - and not root) you'll want to append the --user and --group to the start command to run as that user so that "crashed" mongrels restarted by monit won't start as root

After these changes, restart monit using "/etc/init.d/monit restart" and make sure you receive an e-mail from monit stating it's now monitoring. Now, sit back and relax, knowing that monit will keep your application running smooth.

See also: Best Practices for developing, testing, and deploying your app