Automatic Production Log Performance Reports Rawk Logrotate

rails Photo by alphaducentaure

Killing two birds with one stone here…rotating your Rails production.log (in the default scenario, it just grows forever) and monitoring the performance of your application.

First, get rawk.rb. This little script analyzes your production log and produces nice reports showing which requests are taking the most time. Put it somewhere like /usr/local/bin.

Next, you want to create a logrotate config file for your app’s production.log. On a debian system, they live in /etc/logrotate.d. Here’s an example in a file named rails-example:

/var/www/example.com/shared/log/production.log {
	daily
	missingok
	rotate 14
	compress
	delaycompress
	notifempty
	copytruncate
    prerotate
      /usr/local/bin/rawk.rb < /var/www/example.com/shared/log/production.log | mail -s "[example.com] rawk report" somebody@example.com
    endscript
}

This tells logrotate to rotate the production log every day, keep 14 days worth of copies, and before it rotates the log file, it runs rawk on it and mails the result to somebody.


Related Posts

  1. iPhone/iPad UISearchBar and UISearchDisplayController Asynchronous Example
  2. SPF Records with Rails and ActionMailer
  3. Autotest with Rails Tip -- Ignore Files for Less CPU Usage
  4. Google Analytics API with Ruby
  5. My 5 Must-have vim Plugins
You should follow me on Twitter: @patrickxb