Wednesday 7 April 2010

Extracting timings from Rails logs

Just a little tool to extract the timings for requests from the logs

#!/usr/bin/env ruby

ip_address = nil
datetime = nil

ARGV.each do |filename|
File.open(filename, "r").each do |line|
if line =~ /^Processing .*for ([\d\.]+) at (\d\d\d\d\-\d\d\-\d\d \d\d:\d\d:\d\d)/
ip_address = $1
datetime = $2
elsif line =~ /^Completed in (\d+)ms .View: (\d+), DB: (\d+).*http(.*)\]/
puts "#{ip_address}\t#{datetime}\t#{$1}\t#{$2}\t#{$3}\thttp#{$4}"
end
end
end

Give it bunch of logs on the command line and it will output tab separated lines such as:

1.1.1.1 2010-04-05 04:03:03 7 1 4 http://www.example.com/fred

Where the values are as follows:

  1. The ip from which the request was made

  2. The data and time of the request

  3. The overall processing time in ms

  4. The ms timing for the view

  5. The ms timing for the db

  6. The requested url

No comments:

Post a Comment