Question

I've got a rails app that is behind HAProxy and I'd like to ignore all of the Rails logging coming from the pings from the HAProxy servers. The servers are pinging ~1/sec and are really cluttering up the log file.

Was it helpful?

Solution 3

The solution that I ended up going with was relatively low tech.

The goal of using HAProxy is not just to load balance, but to ensure that the nodes that are being directed traffic are actually up. This means that we wanted to have HAProxy not just hit the server to see if its up, but also test that Nginx and Passenger are up and functioning.

I put a static text file in the public assets of the rails project and have HAProxy hit the file. The file will be served up by the full stack and be a decent indicator that the services are up. As its a public asset, the hit does not appear in the log and the spamming is stopped.

Although this does not test much deeper into the Rails stack, the time to implement is lower than any coded solution, it doesn't add any additional complexity to the application and can be rolled into any future applications.

OTHER TIPS

Haven't tested this, but it should work:


class Rails::Rack::Logger
  def call_with_filter(env)
    if env['REMOTE_ADDR'] == '10.0.0.1'
      @app.call(env)
    else
      call_without_filter(env)
    end
  end
  alias_method_chain :call, :filter
end

see railties-3.0.7/lib/rails/rack/logger.rb for the original.

The solution that I opted for was a little bit more systemic. I created a static textfile in the public directory and switched HAProxy to use this as its ping location. There is no logging and is less complex than a code solution.

I did try the example above and was able to get it working, but doing a monkey patch for this issue doesn't seem necessary, however if the requirements were a bit more complex (i.e. HAProxy had to hit the particular controller) then I'd opt for Roman's solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top