Created
February 9, 2012 19:13
-
-
Save denniskuczynski/1782168 to your computer and use it in GitHub Desktop.
Rake Task to parse Rails server logs and produce the WSESSLOG input format for httperf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :wsesslog do | |
desc 'Generate httperf wsesslog file from Rails log file' | |
task :generate do | |
input = ENV['LOG'] | |
if input.empty? | |
puts "ERROR: No log specified!" | |
puts "Run like: rake wsesslog:generate LOG=log/development.log" | |
exit | |
end | |
require File.dirname(__FILE__) + '/../../vendor/plugins/cainlevy-timber/lib/timber' | |
# add to Request | |
Timber::Request.class_eval {include Timber::Plugins::Rails30} | |
logfile = Timber::Log.new(input) | |
while request = logfile.shift | |
method = request.http_method | |
url = request.url | |
wsesslog_string = "#{url} method=#{method}" | |
has_params = request.instance_variables.find_index(:@params).present? | |
if has_params | |
parameters = request.params | |
wsesslog_string << " contents='#{parameters.to_query}'" | |
end | |
puts wsesslog_string | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment