views:

151

answers:

2

I'm trying to set up custom Pingdom monitoring of my Rails application and would like to craft an XML response that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<pingdom_http_custom_check>
  <status>OK</status>
  <response_time>210.22</response_time>
</pingdom_http_custom_check>

Where the response_time value is the time taken for Rails to render the XML response.

I've found some resources for doing this with Mongrel but I'm using Apache Passenger.

I have a solution implemented as a Sinatra-Metal endpoint like this:

class Pingdom < Sinatra::Base  
  set :views, "#{RAILS_ROOT}/app/views/metal"
  get '/pingdom' do
    @start_time = Time.now
    builder :pingdom
  end
end

and then I have a builder view:

xml.instruct!
xml.pingdom_http_custom_check do |pingdom_http_custom_check|
  pingdom_http_custom_check.status("OK")
  pingdom_http_custom_check.response_time((Time.now-@start_time)*1000)
end

(Note the response_time is in milliseconds).

This implementation is sufficient for checking that the application is up but the very fact that it is a metal endpoint means that it's not actually hitting the main Rails application and so isn't really a very good measure of the current response time of my application.

Does anyone have any good suggestions for a better approach?

Cheers, Arfon

+1  A: 

What does the response time indicate? Have you considered using something like scout or new relic instead?

jonnii
A: 

This railscast shows a way of implementing something similar as Rack middleware, propably should'nt be to hard to modify to suit your needs.

http://railscasts.com/episodes/151-rack-middleware

pmh