Skip to content

Instantly share code, notes, and snippets.

@abriening
Created October 25, 2011 21:21
Show Gist options
  • Save abriening/1314326 to your computer and use it in GitHub Desktop.
Save abriening/1314326 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
filename = ARGV.pop
urls = []
processing_method = {}
File.open filename do |f|
while l = f.gets
if l =~ /.* prism rails\[([0-9]+)\]: .* Processing .* \[([A-Z]+)\]/
processing_method[$1] = $2
end
if l =~ /([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]+) prism rails\[([0-9]+)\]: .* Completed in ([0-9]+)ms [^\|]+ \| [^\[\]]+ \[(http[^\|]*)\]/
date = $1
pid = $2
request_time = $3.to_f / 1000.0
url = $4.gsub(/[0-9]+/, ':id').gsub(/\?.*/, '')
method = processing_method[pid]
urls << [request_time,url,date,method]
end
end
end
counts = urls.inject(Hash.new) do |hash, count|
request_time, url, date, method = count
request = "#{method} #{url}"
hash[request] ||= Hash.new(0)
h = hash[request]
h[:request_time] += request_time
h[:total_requests] += 1
if request_time.to_f > h[:max].to_f
h[:max] = request_time
h[:at] = date
end
hash
end
puts %w[url average_request_time total_requests request_time max max_at].join("\t")
counts.each{|k,v| puts [k, v[:request_time] / v[:total_requests], v[:total_requests], v[:request_time], v[:max], v[:at]].join("\t") }; true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment