A pl_analyze log viewer with Merb
Posted by Ivan Schneider on May 12, 2008 at 01:23 AM
If you don't know it already, production_log_analyzer is a nice gem which provides different tools to analyze log files of a Rails application. pl_analyze is one of those tools and produces text reports on the time spent in the different actions of your Rails app.
I find these reports already quite useful as they are but I thought they could be more usable if only I could easily change the order in which the actions are presented. So I wrote a tiny application to present my reports in a sortable table.
There's nothing really fancy technically speaking, and it really didn't take too much time to get it done, but I thought I could share the result as well as write down a few notes on the steps I took.
Some home brewed javascript and sorttable.js
I started by writing a bunch of javascript functions to parse the reports and build three html tables with the data.
A search for "javascript sort table" led me to sorttable.js which is unobtrusive and easy to use. I wanted alternate colors on my rows for better readability of my tables so I had to tweak it a little bit.
A taste of Merb
Given the fact that almost all of the action happens on the client side, all I really needed from the server side was a single action for the log upload. I thought it could be a good opportunity to take a first shot at Merb and take advantage of the flat app structure. Even though my Merb app was ridiculously small I still learned a few things along the way.
First I didn't know where to put my static files since creating a public directory didn't work for my flat app. I couldn't get google to help me so I looked through the source and found out quickly enough that I just had to put them in the root dir of my app since the server root was set to an empty string.
I also learned how to disable the sessions (I didn't need them and they were conflicting with the rails app serving this blog). It turned out to be really easy, just had to remove three lines config/init.rb which were configuring these sessions.
It's also worth mentioning that I encountered a few errors thus allowing me to see the Merb exception page which I think is quite neat; nice style, folded code for each line in the stacktrace plus links to open the files directly in TextMate.
I deployed this tiny app on a thin backend with nginx on the front and it's accessible right here. Maybe some people will find this a bit useful, i know i do. I'm looking forward to reading any comment you may have.
Comments
There are 0 comments on this post. Post yours →
Post a comment
Required fields in bold.