Automatic production.log performance reports: RAWK + logrotate Mar 18
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.
Add a comment