Monitoring Rails POST requests

Posted by Jesper on March 19, 2010

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 < ApplicationController

skip_before_filter :verify_authenticity_token, :only => :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.

Trackbacks

Trackbacks are closed.

Comments

Comments are closed.