Monitoring Rails POST requests

March 19, 2010 — Leave a comment

Just found this draft post, that I had almost forgotten about. If you need to monitor POST requests to your Rails application for whatever reason, here is an easy way of doing it:

class HomeController  :post_up
  
  def index
  end
  
  # monitored by http://uptime.alal.com/uptime/
  # this will test if Rails is up and responding to GETs and POSTs
  def rails_up
    url = URI.parse(url_for(:action => 'post_up'))
    res = Net::HTTP.post_form(url, {})
    
    # body will be "success" if POST request is successful
    render :text => res.body
  rescue Exception => e
    render :text => "error: #{e.to_s}"
  end
  
  # verify that POST requests are working
  # we've had problems with Apache segfaulting on POSTs
  def post_up
    render :text => request.post? ? "success" : "only POST allowed"
  end
end

Only downside to this, is that it generates an additional request for every request to /rails_up. If you run a low number of Mongrels or Passenger instances, this might be a problem.

No Comments

Be the first to start the conversation!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s