<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hungry Machine &#187; database</title>
	<atom:link href="http://blog.hungrymachine.com/tag/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hungrymachine.com</link>
	<description>The guys behind LivingSocial</description>
	<lastBuildDate>Sun, 25 Oct 2009 15:08:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Monitoring Rails Apps:  Pulse + More</title>
		<link>http://blog.hungrymachine.com/2007/10/26/monitoring-rails-apps-pulse-more/</link>
		<comments>http://blog.hungrymachine.com/2007/10/26/monitoring-rails-apps-pulse-more/#comments</comments>
		<pubDate>Fri, 26 Oct 2007 20:40:00 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[haproxy]]></category>
		<category><![CDATA[Ops]]></category>

		<guid isPermaLink="false">blog.hungrymachine.com/2007/10/26/monitoring-rails-apps-pulse-more</guid>
		<description><![CDATA[Paul Gross from Thoughtworks recently created a pulse gem. The gem adds a simple action to your rails app, &#8220;/pulse&#8221;, which acts as a heartbeat.
The pulse gem currently defines the method as:


def pulse
   render :text =&#62; &#34;OK&#34;
end


Then you can configure haproxy to monitor your application by hitting  http://server/pulse and verifying the response [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pgrs.net/">Paul Gross</a> from <a href="http://www.thoughtworks.com/">Thoughtworks</a> recently created a <a href="http://www.pgrs.net/2007/10/26/announcing-new-gem-pulse">pulse</a> gem. The gem adds a simple action to your rails app, &#8220;/pulse&#8221;, which acts as a heartbeat.<br/><br/></p>
<p>The pulse gem currently defines the method as:</p>
<div class="CodeRay">
<div class="code">
<pre><span style="color:#080; font-weight:bold">def</span> <span style="color:#06B; font-weight:bold">pulse</span>
   render <span style="color:#A60">:text</span> =&gt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">OK</span><span style="color:#710">&quot;</span></span>
<span style="color:#080; font-weight:bold">end</span></pre>
</div>
</div>
<p>Then you can configure haproxy to monitor your application by hitting  http://server/pulse and verifying the response is &#8220;OK&#8221;. <br/><br/></p>
<p>We&#8217;ve had a similar action in our applications for quite some time, although I really like the idea of externalizing it to a gem.  Our implementation is slightly different though.  Since so many rails applications depend on a database, I instead added:</p>
<div class="CodeRay">
<div class="code">
<pre><span style="color:#080; font-weight:bold">def</span> <span style="color:#06B; font-weight:bold">pulse</span>
    rows = <span style="color:#036; font-weight:bold">ActiveRecord</span>::<span style="color:#036; font-weight:bold">Base</span>.connection.execute(<span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">select 1 from dual</span><span style="color:#710">&quot;</span></span>).num_rows <span style="color:#080; font-weight:bold">rescue</span> <span style="color:#00D; font-weight:bold">0</span>
    render <span style="color:#A60">:text</span> =&gt; rows == <span style="color:#00D; font-weight:bold">1</span> ? <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">OK</span><span style="color:#710">&quot;</span></span> : <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">Error!</span><span style="color:#710">&quot;</span></span>
<span style="color:#080; font-weight:bold">end</span></pre>
</div>
</div>
<p>IIRC, &#8220;select 1 from dual&#8221; is the fastest query you can run against a database, in MySQL, Oracle, and Postgres.  And if you have mutliple databases, you can add union in the one pulse request, or have multiple actions. <br/><br/></p>
<p>Now you are not only testing your application is live, but that it can connect to the database.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hungrymachine.com/2007/10/26/monitoring-rails-apps-pulse-more/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
