<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Scout ~ The Blog comments on The 3 pillars of our Rails Monitoring Stack</title>
    <link>http://blog.scoutapp.com/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Scout ~ The Blog comments</description>
    <item>
      <title>"The 3 pillars of our Rails Monitoring Stack" by derek</title>
      <description>&lt;p&gt;Life as a cross-dresser must be unnerving. I could buy a wig, put some makeup on my adam&amp;#8217;s apple. Buy a skirt. Does a sock-filled bra work for my bosom?&lt;/p&gt;


	&lt;p&gt;With a bit of mood lighting, I might actually look like a woman, but it would be difficult to relax. Knowing my manhood could be exposed in a multitude of ways &amp;#8211; some stubble on my chin, hair on my legs, forgetting to make my voice less deep, etc. would leave me on-edge.&lt;/p&gt;


	&lt;p&gt;In some ways, I feel like I identified with cross-dressers before we solidified our Rails monitoring stack over the past year. I just felt vulnerable &amp;#8211; that one wrong move could send our Rails stack tumbling.&lt;/p&gt;


	&lt;p&gt;We&amp;#8217;ve standardized our setup, and I thought I&amp;#8217;d share the 3 tools we&amp;#8217;re using that make me feel much less like a cross-dresser these days.&lt;/p&gt;


&lt;style type="text/css" media="screen"&gt;
 h2 {
   color: #000
   font-weight:bold
 }
 table#monitoring {
   border: 1px solid #999;
   border-width: 1px 0px;
 }
  #monitoring td {
    text-align:center;
    vertical-align:top;
  }
  #monitoring h2, #monitoring h3 {
    text-align: center;
    font-family: Georgia;
    font-size: 18px;
    color:#4764A8;
  }
  #monitoring h3 {
    font-size:15px;
    color:#333;
  }
  #monitoring strong {
    font-family: Georgia;
    font-size:13px;
  }
  #monitoring a{
    text-decoration: underline;
  }
  #monitoring strong a:hover {
    color:#fff;
    background:#885d28;
  }
  #monitoring td.small {
    padding:5px 0px 15px 0px;
    font-size: 10px;
  }
  code {
    font-size:10px;
  }
  .subhead {
    font-size: 16px;
    font-family:Arial;
      margin:0;
      line-height:120%;
      font-weight:normal;
      color:#4764A8;
  }
&lt;/style&gt;

	&lt;h2&gt;The 3 pillars of our Rails monitoring stack&lt;/h2&gt;


	&lt;p&gt;We break Rails monitoring into the 3 parts below (along with the tools we use):&lt;/p&gt;


&lt;table id="monitoring"&gt;
  &lt;tr&gt;
    &lt;th&gt;
      &lt;h2&gt;Process Monitoring&lt;/h2&gt;
    &lt;/th&gt;
    &lt;th&gt;
      &lt;h2&gt;System Performance&lt;/h2&gt;
    &lt;th&gt;
      &lt;h2&gt;Exception Notifications&lt;/h2&gt;
    &lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;
      &lt;img src="http://img.skitch.com/20080822-q5han844h22x7eqmyuj3dasr4u.jpg" alt="skitched-20080822-140434.jpg"/&gt;
      &lt;h3&gt;&amp;#8220;The Diaper&amp;#8221;&lt;/h2&gt;
      A safeguard for emergencies
    &lt;/td&gt;
    &lt;td&gt;
      &lt;img src="http://img.skitch.com/20080822-fh43pmeqgxsa78nc6q43ir3bka.jpg" alt="skitched-20080822-140537.jpg"/&gt;
      &lt;h3&gt;&amp;#8220;The Nerves&amp;#8221;&lt;/h2&gt;
      Preventing future problems
    &lt;/td&gt;
    &lt;td&gt;
      &lt;img src="http://img.skitch.com/20080822-t13yhgiam7rp5hd42w4x1y4hcg.jpg" alt="skitched-20080822-140602.jpg"/&gt;
      &lt;h3&gt;&amp;#8220;The Megaphone&amp;#8221;&lt;/h2&gt;
      A loud voice when your app is breaking
    &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;
      &lt;a href="http://www.tildeslash.com/monit/"&gt;&lt;strong&gt;Monit&lt;/strong&gt;&lt;/a&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;a href="http://scoutapp.com"&gt;&lt;strong&gt;Scout&lt;/strong&gt;&lt;/a&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;a href="http://github.com/rails/exception_notification/tree/master"&gt;&lt;strong&gt;Exception Notification plugin&lt;/strong&gt;&lt;/a&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td class="small"&gt;
      Ensure Mongrels are running &amp;#38; restart leaking processes
    &lt;/td&gt;
    &lt;td class="small"&gt;
      Catch disturbing trends before they become problems &amp;#8211; disk space usage,
      server load, slow requests, etc.
    &lt;/td&gt;
    &lt;td class="small"&gt;
      Organizing and collecting application exceptions
    &lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;p&gt;
So, to be clear, even though we built Scout, we use a combination of tools to make sure our Rails apps are running. 
&lt;/p&gt;

&lt;h2&gt;The diaper &amp;#8211; Process monitoring with Monit&lt;/h2&gt;


&lt;p style="float:left;padding:5px 10px 10px 0px"&gt;&lt;img src="http://farm1.static.flickr.com/73/194317794_247d280969_m.jpg" alt="" /&gt;&lt;/p&gt;

	&lt;p&gt;If a key process, like a Mongrel server containing a Rails application, dies or leaks memory, you often want to restart it immediately. Frankly it&amp;#8217;s panic time &amp;#8211; it could happen at any time, and you may not have time to figure out what went wrong. You just want the application back up. We&amp;#8217;ve been using the open-source tool &lt;a href="http://www.tildeslash.com/monit/"&gt;Monit&lt;/a&gt; for this task for some time (&lt;a href="http://god.rubyforge.org/"&gt;God&lt;/a&gt;, a Ruby-powered process and task monitoring tool is another option).&lt;/p&gt;


&lt;div class="subhead" style="clear:left"&gt;Configure a restart script&lt;/div&gt;

	&lt;p&gt;I&amp;#8217;m not going to cover the monit installation process (&lt;a href="http://www.tildeslash.com/monit/doc/"&gt;monit&amp;#8217;s documentation&lt;/a&gt;), but I&amp;#8217;ll show a simple example for restarting a Mongrel process.&lt;/p&gt;


Here&amp;#8217;s how we restart a Mongrel process that:
	&lt;ul&gt;
	&lt;li&gt;Is dead&lt;/li&gt;
		&lt;li&gt;Is using over 100 MB in memory&lt;/li&gt;
	&lt;/ul&gt;


&lt;pre&gt;
&lt;code&gt;
check process mongrel-8000 with pidfile /var/run/mongrel_cluster/mongrel.8000.pid  group mongrel_staging
  start program = "/usr/bin/mongrel_rails cluster::start -C /etc/mongrel_cluster/app_name.yml --only 8000 --clean" 
    as uid deploy and gid deploy
  stop program  = "/usr/bin/mongrel_rails cluster::stop -C /etc/mongrel_cluster/app_name.yml --only 8000 --force --clean" 
    as uid deploy and gid deploy
  if totalmem &amp;gt; 100.0 MB for 5 cycles then restart
&lt;/code&gt;
&lt;/pre&gt;
&lt;br/&gt;

	&lt;p&gt;(For automating the setup of these configuration&amp;#8212;based on your mongrel configuration, check out the &lt;a href="http://github.com/seebq/capistrano_monit/tree/master"&gt;capistrano_monit extension&lt;/a&gt;)&lt;/p&gt;


	&lt;p&gt;It&amp;#8217;s easy to test your monit setup, once it is in place:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Tail your system message log (i.e. tail -f /var/log/messages)&lt;/li&gt;
		&lt;li&gt;Manually kill the process&lt;/li&gt;
		&lt;li&gt;Watch for Monit to restart the process in the messages log. It looks like this:&lt;/li&gt;
	&lt;/ol&gt;


&lt;pre&gt;&lt;code&gt;
Aug 22 13:57:13 test monit[32613]: 'mongrel_staging-9000' process is not running 
Aug 22 13:57:13 test monit[32613]: 'mongrel_staging-9000' trying to restart 
Aug 22 13:57:13 test monit[32613]: 'mongrel_staging-9000' start: /usr/bin/mongrel_rails 
Aug 22 13:58:19 test monit[32613]: 'mongrel_staging-9000' process is running with pid 678
&lt;/code&gt;&lt;/pre&gt;
&lt;br/&gt;
&lt;div class="subhead" style="clear:left"&gt;It&amp;#8217;s just a diaper &amp;#8211; it won&amp;#8217;t solve underlying problems&lt;/div&gt;

	&lt;p&gt;Monit will ensure we&amp;#8217;re not totally dead, but it won&amp;#8217;t prevent problems from happening in the future. It can restart a memory-leaking process, but it won&amp;#8217;t give us any clues about the leak. It&amp;#8217;s not preventative medicine. We need some preventive medicine.&lt;/p&gt;


	&lt;h2&gt;The nerves &amp;#8211; system performance with Scout&lt;/h2&gt;


&lt;p style="float:left;padding:5px 10px 10px 0px"&gt;&lt;img src="http://farm1.static.flickr.com/163/389765638_7e47d10a69_m.jpg" alt="" /&gt;&lt;/p&gt;

	&lt;p&gt;When I was a kid, I once wished I that I couldn&amp;#8217;t feel pain. I was awkward and fell down a lot. As I got older, I realized some pain is good &amp;#8211; it&amp;#8217;s our body&amp;#8217;s way of saying &amp;#8220;Hey, slow down a second &amp;#8211; you need to check this out&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://scoutapp.com"&gt;Scout&lt;/a&gt; is our nerve center. We use it to monitor trends in our Rails stack. Has disk space usage quickly increased? Has there been a spike the in the server load? How many more users can our current hardware handle?&lt;/p&gt;


	&lt;p&gt;For example, a while back we noticed that disk space usage was increasing at an alarming rate on one of our servers. We caught it early-on by looking at the dramatic increase in disk space usage from the graph below:&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://img.skitch.com/20080822-d86fqi2cqyr5c3srbp9xn64hpy.jpg" alt="[NEW ERROR] Scout ~ iBridge"/&gt;&lt;/p&gt;


	&lt;p&gt;The problem? An issue with an Amazon S3 backup. We fixed the problem far before it became an issue, and as you can see from the graph, things returned to normal.&lt;/p&gt;


	&lt;p&gt;In addition to &lt;a href="http://scoutapp.com/plugin_urls/6-disk-usage"&gt;disk usage&lt;/a&gt;, we use Scout to monitor our &lt;a href="http://scoutapp.com/plugin_urls/3-ruby-on-rails-request-monitoring"&gt;Rails requests&lt;/a&gt;, &lt;a href="http://scoutapp.com/plugin_urls/4-server-load"&gt;server load&lt;/a&gt;, &lt;a href="http://scoutapp.com/plugin_urls/1-process-usage"&gt;memory usage&lt;/a&gt;, &lt;a href="http://scoutapp.com/plugin_urls"&gt;and more&lt;/a&gt;.&lt;/p&gt;


	&lt;h2&gt;The megaphone &amp;#8211; Exception notifications with the Exception Notification plugin&lt;/h2&gt;


&lt;p style="float:left;padding:5px 10px 10px 0px"&gt;&lt;img src="http://farm1.static.flickr.com/204/470341923_14e8dbc101_m.jpg" alt="" /&gt;&lt;/p&gt;

	&lt;p&gt;We&amp;#8217;ve got most of our vitals covered &amp;#8211; our Rails app will restart when it dies automatically with Monit. We&amp;#8217;ll be able to identify system resource trends quickly with Scout. However, things often go wrong when our application server and Rails stack is running fine.&lt;/p&gt;


	&lt;p&gt;The tried-and-true method for instant exception notifications is the &lt;a href="http://github.com/rails/exception_notification/tree/master"&gt;Exception Notification plugin&lt;/a&gt;. If you&amp;#8217;re part of a development team, you might want to look at &lt;a href="http://hoptoadapp.com/"&gt;Hoptoad&lt;/a&gt;. Hoptoad provides organization to the typical flood of emails the Exception Notification plugin can generate. You install the Hoptoad plugin, which contacts the Hoptoadd server when an exception occurs. Hoptoad eliminates duplicate emails and makes it easier to organize exceptions across applications.&lt;/p&gt;


	&lt;h2&gt;It&amp;#8217;s about piece-of-mind&lt;/h2&gt;


	&lt;p&gt;From start-to-finish, you can have Monit setup and tested in a couple of hours (at most). The Scout and Exception Notification plugin/Hoptoadd installation process should be measured in minutes. It&amp;#8217;s time well-spent knowing things are in order when you aren&amp;#8217;t in front of your computer.&lt;/p&gt;</description>
      <pubDate>Tue,  9 Sep 2008 00:44:00 CDT</pubDate>
      <guid>&lt;a href="/articles/2008/09/09/rails-monitoring-pillars"&gt;The 3 pillars of our Rails Monitoring Stack&lt;/a&gt;</guid>
      <link>&lt;a href="/articles/2008/09/09/rails-monitoring-pillars"&gt;The 3 pillars of our Rails Monitoring Stack&lt;/a&gt;</link>
    </item>
  </channel>
</rss>
