Created
February 14, 2012 20:39
-
-
Save denniskuczynski/1830188 to your computer and use it in GitHub Desktop.
Rake Task to parse Rails server logs and produce the Trample configuration files for Trample load testing tool
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 :trample do | |
desc 'Generate Trample config file from Rails log file' | |
task :generate do | |
input = ENV['LOG'] | |
if input.empty? | |
puts "ERROR: No log specified!" | |
puts "Run like: rake trample: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} | |
puts "Trample.configure do" | |
puts " concurrency 1" | |
puts " iterations 1" | |
puts " login do" | |
puts " end" | |
logfile = Timber::Log.new(input) | |
while request = logfile.shift | |
method = request.http_method | |
url = request.url | |
request_string = " #{method.downcase} \"#{url}\"" | |
has_params = request.instance_variables.find_index(:@params).present? | |
if has_params and method != "GET" | |
parameters = request.params | |
parameters = parameters.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} #Convert string keys to symbols | |
request_string << " do\n #{parameters.inspect} \n end" | |
end | |
puts request_string | |
end | |
puts "end" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment