bin/request-log-analyzer in wvanbergen-request-log-analyzer-0.1.2 vs bin/request-log-analyzer in wvanbergen-request-log-analyzer-0.2.2

- old
+ new

@@ -1,27 +1,31 @@ #!/usr/bin/ruby require File.dirname(__FILE__) + '/../lib/command_line/arguments' +require File.dirname(__FILE__) + '/../lib/base/log_parser' +require File.dirname(__FILE__) + '/../lib/base/summarizer' require File.dirname(__FILE__) + '/../lib/rails_analyzer/log_parser' require File.dirname(__FILE__) + '/../lib/rails_analyzer/summarizer' +require File.dirname(__FILE__) + '/../lib/merb_analyzer/log_parser' +require File.dirname(__FILE__) + '/../lib/merb_analyzer/summarizer' require File.dirname(__FILE__) + '/../lib/bashcolorizer' require File.dirname(__FILE__) + '/../lib/ruby-progressbar/progressbar.rb' puts "Request log analyzer, by Willem van Bergen and Bart ten Brinke\n\n" # Substitutes variable elements in a url (like the id field) with a fixed string (like ":id") -# This is used to aggregate simular requests. +# This is used to aggregate simular requests. # <tt>request</tt> The request to evaluate. # Returns uniformed url string. # Raises on mailformed request. def request_hasher(request) if request[:url] url = request[:url].downcase.split(/^http[s]?:\/\/[A-z0-9\.-]+/).last.split('?').first # only the relevant URL part url << '/' if url[-1] != '/'[0] && url.length > 1 # pad a trailing slash for consistency - url.gsub!(/\/\d+-\d+-\d+/, '/:date') # Combine all (year-month-day) queries - url.gsub!(/\/\d+-\d+/, '/:month') # Combine all date (year-month) queries - url.gsub!(/\/\d+/, '/:id') # replace identifiers in URLs + url.gsub!(/\/\d+-\d+-\d+(\/|$)/, '/:date') # Combine all (year-month-day) queries + url.gsub!(/\/\d+-\d+(\/|$)/, '/:month') # Combine all date (year-month) queries + url.gsub!(/\/\d+[\w-]*/, '/:id') # replace identifiers in URLs return url elsif request[:controller] && request[:action] return "#{request[:controller]}##{request[:action]}" else @@ -46,10 +50,11 @@ begin $arguments = CommandLine::Arguments.parse do |command_line| command_line.switch(:guess_database_time, :g) command_line.switch(:fast, :f) command_line.switch(:colorize, :z) + command_line.switch(:merb, :m) command_line.flag(:output, :alias => :o) command_line.flag(:amount, :alias => :c) command_line.required_files = 1 end @@ -58,18 +63,33 @@ puts load File.dirname(__FILE__) + "/../output/usage.rb" exit(0) end -$summarizer = RailsAnalyzer::Summarizer.new(:calculate_database => $arguments[:guess_database_time]) -$summarizer.blocker_duration = 1.0 -line_types = $arguments[:fast] ? [:completed] : [:started, :completed, :failed] +if $arguments[:merb] + $summarizer = MerbAnalyzer::Summarizer.new(:calculate_database => $arguments[:guess_database_time]) +else + $summarizer = RailsAnalyzer::Summarizer.new(:calculate_database => $arguments[:guess_database_time]) +end +if $arguments[:fast] + line_types = [:completed] +elsif $arguments[:merb] + line_types = MerbAnalyzer::LogParser::LOG_LINES.keys +else + line_types = RailsAnalyzer::LogParser::LOG_LINES.keys +end + # Walk through al the files given via the arguments. $arguments.files.each do |log_file| puts "Processing #{line_types.join(', ')} log lines from #{log_file}..." - parser = RailsAnalyzer::LogParser.new(log_file) + + if $arguments[:merb] + parser = MerbAnalyzer::LogParser.new(log_file) + else + parser = RailsAnalyzer::LogParser.new(log_file) + end # add progress bar unless $arguments[:fast] pbar = ProgressBar.new(green(log_file), File.size(log_file)) parser.progress { |pos, total| (pos == :finished) ? pbar.finish : pbar.set(pos) }