wvanbergen-request-log-analyzer 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. data/{README → README.textile} +29 -36
  2. data/Rakefile +3 -70
  3. data/TODO +43 -8
  4. data/bin/request-log-analyzer +32 -99
  5. data/lib/base/summarizer.rb +14 -0
  6. data/lib/bashcolorizer.rb +1 -1
  7. data/lib/command_line/arguments.rb +15 -2
  8. data/lib/command_line/flag.rb +12 -0
  9. data/lib/rails_analyzer/summarizer.rb +12 -4
  10. data/lib/rails_analyzer/virtual_mongrel.rb +91 -0
  11. data/lib/request_log_analyzer/aggregator/base.rb +34 -0
  12. data/lib/request_log_analyzer/aggregator/database.rb +86 -0
  13. data/lib/request_log_analyzer/aggregator/echo.rb +10 -0
  14. data/lib/request_log_analyzer/aggregator/summarizer.rb +53 -0
  15. data/lib/request_log_analyzer/controller.rb +90 -0
  16. data/lib/request_log_analyzer/file_format/merb.rb +30 -0
  17. data/lib/request_log_analyzer/file_format/rails.rb +84 -0
  18. data/lib/request_log_analyzer/file_format.rb +91 -0
  19. data/lib/request_log_analyzer/log_parser.rb +122 -0
  20. data/lib/request_log_analyzer/request.rb +72 -0
  21. data/lib/request_log_analyzer.rb +5 -0
  22. data/output/blockers.rb +2 -4
  23. data/output/errors.rb +1 -2
  24. data/output/hourly_spread.rb +3 -3
  25. data/output/mean_db_time.rb +1 -2
  26. data/output/mean_rendering_time.rb +2 -3
  27. data/output/mean_time.rb +2 -3
  28. data/output/most_requested.rb +1 -2
  29. data/output/timespan.rb +10 -8
  30. data/output/total_db_time.rb +2 -3
  31. data/output/total_time.rb +2 -3
  32. data/output/usage.rb +3 -2
  33. data/spec/controller_spec.rb +33 -0
  34. data/spec/database_inserter_spec.rb +81 -0
  35. data/{test/log_fragments/merb_1.log → spec/fixtures/merb.log} +0 -0
  36. data/spec/fixtures/multiple_files_1.log +5 -0
  37. data/spec/fixtures/multiple_files_2.log +2 -0
  38. data/{test/log_fragments/fragment_1.log → spec/fixtures/rails_1x.log} +5 -5
  39. data/{test/log_fragments/fragment_3.log → spec/fixtures/rails_22.log} +2 -2
  40. data/spec/fixtures/rails_22_cached.log +10 -0
  41. data/spec/fixtures/rails_unordered.log +24 -0
  42. data/{test/log_fragments/fragment_2.log → spec/fixtures/syslog_1x.log} +0 -0
  43. data/spec/fixtures/test_file_format.log +11 -0
  44. data/spec/fixtures/test_language_combined.log +14 -0
  45. data/spec/fixtures/test_order.log +16 -0
  46. data/spec/line_definition_spec.rb +34 -0
  47. data/spec/log_parser_spec.rb +92 -0
  48. data/spec/merb_format_spec.rb +58 -0
  49. data/spec/rails_format_spec.rb +95 -0
  50. data/spec/request_spec.rb +76 -0
  51. data/spec/spec_helper.rb +49 -0
  52. data/spec/summarizer_spec.rb +109 -0
  53. data/tasks/github-gem.rake +177 -0
  54. data/tasks/request_log_analyzer.rake +10 -0
  55. data/tasks/rspec.rake +6 -0
  56. data/test/base_summarizer_test.rb +30 -0
  57. metadata +46 -22
  58. data/bin/request-log-database +0 -81
  59. data/lib/base/log_parser.rb +0 -78
  60. data/lib/base/record_inserter.rb +0 -139
  61. data/lib/merb_analyzer/log_parser.rb +0 -26
  62. data/lib/rails_analyzer/log_parser.rb +0 -35
  63. data/lib/rails_analyzer/record_inserter.rb +0 -39
  64. data/test/merb_log_parser_test.rb +0 -39
  65. data/test/rails_log_parser_test.rb +0 -95
  66. data/test/record_inserter_test.rb +0 -45
  67. data/test/tasks.rake +0 -8
@@ -0,0 +1,95 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe RequestLogAnalyzer::LogParser, "Rails without combined requests" do
4
+ include RequestLogAnalyzerSpecHelper
5
+
6
+ before(:each) do
7
+ @log_parser = RequestLogAnalyzer::LogParser.new(:rails, :combined_requests => false)
8
+ end
9
+
10
+ it "should parse a stream and find valid requests" do
11
+ io = File.new(log_fixture(:rails_1x), 'r')
12
+ @log_parser.parse_io(io) do |request|
13
+ request.should be_kind_of(RequestLogAnalyzer::Request)
14
+ end
15
+ io.close
16
+ end
17
+
18
+ it "should find 8 requests when lines are not linked" do
19
+ requests = []
20
+ @log_parser.parse_file(log_fixture(:rails_1x)) { |request| requests << request }
21
+ requests.length.should == 8
22
+ requests.each { |r| r.should be_single_line }
23
+ requests.select { |r| r.line_type == :started }.should have(4).items
24
+ end
25
+ end
26
+
27
+
28
+ describe RequestLogAnalyzer::LogParser, "Rails with combined requests" do
29
+ include RequestLogAnalyzerSpecHelper
30
+
31
+ before(:each) do
32
+ @log_parser = RequestLogAnalyzer::LogParser.new(:rails, :combined_requests => true)
33
+ end
34
+
35
+ it "should have a valid language definitions" do
36
+ @log_parser.file_format.should be_valid
37
+ end
38
+
39
+ it "should find 4 completed requests when lines are linked" do
40
+ @log_parser.should_not_receive(:warn)
41
+ @log_parser.should_receive(:handle_request).exactly(4).times
42
+ @log_parser.parse_file(log_fixture(:rails_1x))
43
+ end
44
+
45
+ it "should parse a Rails 2.2 request properly" do
46
+ @log_parser.should_not_receive(:warn)
47
+ @log_parser.parse_file(log_fixture(:rails_22)) do |request|
48
+ request.should =~ :started
49
+ request.should =~ :completed
50
+
51
+ request[:controller].should == 'PageController'
52
+ request[:action].should == 'demo'
53
+ request[:url].should == 'http://www.example.coml/demo'
54
+ request[:status].should == 200
55
+ request[:duration].should == 0.614
56
+ request[:db].should == 0.031
57
+ request[:view].should == 0.120
58
+ end
59
+ end
60
+
61
+ it "should parse a syslog file with prefix correctly" do
62
+ @log_parser.should_not_receive(:warn)
63
+ @log_parser.parse_file(log_fixture(:syslog_1x)) do |request|
64
+
65
+ request.should be_completed
66
+ request.should be_combined
67
+
68
+ request[:controller].should == 'EmployeeController'
69
+ request[:action].should == 'index'
70
+ request[:url].should == 'http://example.com/employee.xml'
71
+ request[:status].should == 200
72
+ request[:duration].should == 0.21665
73
+ request[:db].should == 0.0
74
+ request[:view].should == 0.00926
75
+ end
76
+ end
77
+
78
+ it "should parse cached requests" do
79
+ @log_parser.should_not_receive(:warn)
80
+ @log_parser.parse_file(log_fixture(:rails_22_cached)) do |request|
81
+ request.should be_completed
82
+ request.should be_combined
83
+ request =~ :cache_hit
84
+ end
85
+ end
86
+
87
+ it "should detect unordered requests in the logs" do
88
+ @log_parser.should_not_receive(:handle_request)
89
+ # the first Processing-line will not give a warning, but the next one will
90
+ @log_parser.should_receive(:warn).with(:unclosed_request, anything).once
91
+ # Both Completed ;ines will give a warning
92
+ @log_parser.should_receive(:warn).with(:no_current_request, anything).twice
93
+ @log_parser.parse_file(log_fixture(:rails_unordered))
94
+ end
95
+ end
@@ -0,0 +1,76 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe RequestLogAnalyzer::Request, :single_line do
4
+
5
+ before(:each) do
6
+ @single_line_request = RequestLogAnalyzer::Request.new(TestFileFormat)
7
+ @single_line_request << { :line_type => :test, :lineno => 1, :test_capture => 'awesome!' }
8
+ end
9
+
10
+ it "should include the file format module" do
11
+ (class << @single_line_request; self; end).ancestors.include?(TestFileFormat)
12
+ end
13
+
14
+ it "should be single if only one line has been added" do
15
+ @single_line_request.should be_single_line
16
+ @single_line_request.should_not be_empty
17
+ @single_line_request.should_not be_combined
18
+ end
19
+
20
+ it "should not be a completed request" do
21
+ @single_line_request.should_not be_completed
22
+ end
23
+
24
+ it "should take the line type of the first line as global line_type" do
25
+ @single_line_request.line_type.should == :test
26
+ @single_line_request.should =~ :test
27
+ end
28
+
29
+ it "should return the first field value" do
30
+ @single_line_request[:test_capture].should == 'awesome!'
31
+ end
32
+
33
+ it "should return nil if no such field is present" do
34
+ @single_line_request[:nonexisting].should be_nil
35
+ end
36
+ end
37
+
38
+
39
+ describe RequestLogAnalyzer::Request, :combined do
40
+
41
+ before(:each) do
42
+ @combined_request = RequestLogAnalyzer::Request.new(TestFileFormat)
43
+ @combined_request << { :line_type => :first, :lineno => 1, :name => 'first line!' }
44
+ @combined_request << { :line_type => :test, :lineno => 4, :test_capture => 'testing' }
45
+ @combined_request << { :line_type => :test, :lineno => 7, :test_capture => 'testing some more' }
46
+ @combined_request << { :line_type => :last, :lineno => 10, :time => 0.03 }
47
+ end
48
+
49
+ it "should be a combined request when more lines are added" do
50
+ @combined_request.should be_combined
51
+ @combined_request.should_not be_single_line
52
+ @combined_request.should_not be_empty
53
+ end
54
+
55
+ it "should be a completed request" do
56
+ @combined_request.should be_completed
57
+ end
58
+
59
+ it "should recognize all line types" do
60
+ [:first, :test, :last].each { |type| @combined_request.should =~ type }
61
+ end
62
+
63
+ it "should detect the correct field value" do
64
+ @combined_request[:name].should == 'first line!'
65
+ @combined_request[:time].should == 0.03
66
+ end
67
+
68
+ it "should detect the first matching field value" do
69
+ @combined_request.first(:test_capture).should == 'testing'
70
+ end
71
+
72
+ it "should detect the every matching field value" do
73
+ @combined_request.every(:test_capture).should == ['testing', "testing some more"]
74
+ end
75
+
76
+ end
@@ -0,0 +1,49 @@
1
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'rubygems'
4
+ require 'spec'
5
+
6
+ require 'request_log_analyzer'
7
+
8
+ module RequestLogAnalyzerSpecHelper
9
+
10
+ def log_fixture(name)
11
+ File.dirname(__FILE__) + "/fixtures/#{name}.log"
12
+ end
13
+
14
+ end
15
+
16
+ module TestFileFormat
17
+
18
+ module Summarizer
19
+ def self.included(base)
20
+ # monkey patching for summarizer here :-)
21
+ end
22
+ end
23
+
24
+ module LogParser
25
+ def self.included(base)
26
+ # monkey patching for log parser here :-)
27
+ end
28
+ end
29
+
30
+ LINE_DEFINITIONS = {
31
+ :first => {
32
+ :header => true,
33
+ :teaser => /processing /,
34
+ :regexp => /processing request (\d+)/,
35
+ :captures => [{:request_no => :integer}]
36
+ },
37
+ :test => {
38
+ :teaser => /testing /,
39
+ :regexp => /testing is (\w+)/,
40
+ :captures => [{:test_capture => :string}]
41
+ },
42
+ :last => {
43
+ :footer => true,
44
+ :teaser => /finishing /,
45
+ :regexp => /finishing request (\d+)/,
46
+ :captures => [{:request_no => :integer}]
47
+ }
48
+ }
49
+ end
@@ -0,0 +1,109 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'request_log_analyzer/aggregator/summarizer'
3
+
4
+ describe RequestLogAnalyzer::Aggregator::Summarizer, :single_line do
5
+
6
+ before(:each) do
7
+ @summarizer = RequestLogAnalyzer::Aggregator::Summarizer.new(TestFileFormat, :combined_requests => false)
8
+ @summarizer.prepare
9
+
10
+ @test_request_1 = RequestLogAnalyzer::Request.create(TestFileFormat, {:line_type => :first, :request_no => 564})
11
+ @test_request_2 = RequestLogAnalyzer::Request.create(TestFileFormat, {:line_type => :test, :test_capture => 'awesome'})
12
+ @test_request_3 = RequestLogAnalyzer::Request.create(TestFileFormat, {:line_type => :last, :request_no => 564})
13
+ end
14
+
15
+ it "should include the file format Summarizer module" do
16
+ metaclass = (class << @summarizer; self; end)
17
+ metaclass.ancestors.should include(TestFileFormat::Summarizer)
18
+ @summarizer.class.ancestors.should_not include(TestFileFormat::Summarizer)
19
+ end
20
+
21
+ it "should set the default bucket for a new line type" do
22
+ @summarizer.should_receive(:default_bucket_content).once.and_return(:count => 0)
23
+ @summarizer.aggregate(@test_request_1)
24
+ end
25
+
26
+ it "should request a bucket name for the hash" do
27
+ @summarizer.should_receive(:bucket_for).with(@test_request_1).once.and_return('all')
28
+ @summarizer.aggregate(@test_request_1)
29
+ end
30
+
31
+ it "should register" do
32
+ @summarizer.should_receive(:update_bucket).with(anything, @test_request_1).once
33
+ @summarizer.aggregate(@test_request_1)
34
+ end
35
+
36
+ it "should have buckets for every line type on the first level" do
37
+ @summarizer.aggregate(@test_request_1)
38
+ @summarizer.aggregate(@test_request_2)
39
+ @summarizer.aggregate(@test_request_3)
40
+ @summarizer.buckets.should have(3).items
41
+ @summarizer.buckets.should have_key(:first)
42
+ @summarizer.buckets.should have_key(:test)
43
+ @summarizer.buckets.should have_key(:last)
44
+ end
45
+
46
+ it "should aggregate in the same bucket" do
47
+ @summarizer.should_receive(:bucket_for).exactly(3).times.and_return('all')
48
+ 3.times { @summarizer.aggregate(@test_request_2) }
49
+ @summarizer.buckets[:test].should have(1).items
50
+ end
51
+
52
+ it "should aggregate in different buckets based on" do
53
+ 4.times do |n|
54
+ @summarizer.stub!(:bucket_for).and_return("bucket #{n % 2}") # buckets 1 and 2
55
+ @summarizer.aggregate(@test_request_2)
56
+ end
57
+ @summarizer.buckets[:test].should have(2).items
58
+ end
59
+
60
+ end
61
+
62
+ describe RequestLogAnalyzer::Aggregator::Summarizer, :combined_requests do
63
+
64
+ before(:each) do
65
+ @summarizer = RequestLogAnalyzer::Aggregator::Summarizer.new(TestFileFormat, :combined_requests => true)
66
+ @summarizer.prepare
67
+
68
+ @test_request = RequestLogAnalyzer::Request.create(TestFileFormat,
69
+ {:line_type => :first, :request_no => 564},
70
+ {:line_type => :test, :test_capture => 'blug'},
71
+ {:line_type => :last, :request_no => 564})
72
+ end
73
+
74
+ it "should include the file format Summarizer module" do
75
+ metaclass = (class << @summarizer; self; end)
76
+ metaclass.ancestors.should include(TestFileFormat::Summarizer)
77
+ @summarizer.class.ancestors.should_not include(TestFileFormat::Summarizer)
78
+ end
79
+
80
+ it "should set the default bucket for a new line type" do
81
+ @summarizer.should_receive(:default_bucket_content).once.and_return(:count => 0)
82
+ @summarizer.aggregate(@test_request)
83
+ end
84
+
85
+ it "should register" do
86
+ @summarizer.should_receive(:update_bucket).with(anything, @test_request).once
87
+ @summarizer.aggregate(@test_request)
88
+ end
89
+
90
+ it "should aggregate in the same bucket" do
91
+ 3.times { @summarizer.aggregate(@test_request) }
92
+ @summarizer.buckets.should have(1).items
93
+ end
94
+
95
+ it "should aggregate in the same bucket" do
96
+ @summarizer.should_receive(:bucket_for).exactly(3).times.and_return('all')
97
+ 3.times { @summarizer.aggregate(@test_request) }
98
+ @summarizer.buckets.should have(1).items
99
+ end
100
+
101
+ it "should aggregate in different buckets based on" do
102
+ 4.times do |n|
103
+ @summarizer.stub!(:bucket_for).and_return("bucket #{n % 2}") # buckets 1 and 2
104
+ @summarizer.aggregate(@test_request)
105
+ end
106
+ @summarizer.buckets.should have(2).items
107
+ end
108
+
109
+ end
@@ -0,0 +1,177 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/tasklib'
4
+ require 'date'
5
+
6
+ module Rake
7
+
8
+ class GithubGem < TaskLib
9
+
10
+ attr_accessor :name
11
+ attr_accessor :specification
12
+
13
+ def self.define_tasks!
14
+ gem_task_builder = Rake::GithubGem.new
15
+ gem_task_builder.register_all_tasks!
16
+ end
17
+
18
+
19
+ def initialize
20
+ reload_gemspec!
21
+ end
22
+
23
+ def register_all_tasks!
24
+ namespace(:gem) do
25
+ desc "Updates the file lists for this gem"
26
+ task(:manifest) { manifest_task }
27
+
28
+ desc "Builds a ruby gem for #{@name}"
29
+ task(:build => [:manifest]) { build_task }
30
+
31
+ desc "Installs the ruby gem for #{@name} locally"
32
+ task(:install => [:build]) { install_task }
33
+
34
+ desc "Uninstalls the ruby gem for #{@name} locally"
35
+ task(:uninstall) { uninstall_task }
36
+
37
+ desc "Releases a new version of #{@name}"
38
+ task(:release) { release_task }
39
+ end
40
+ end
41
+
42
+
43
+
44
+ protected
45
+
46
+ def reload_gemspec!
47
+ raise "No gemspec file found!" if gemspec_file.nil?
48
+ spec = File.read(gemspec_file)
49
+ @specification = eval(spec)
50
+ @name = specification.name
51
+ end
52
+
53
+ def run_command(command)
54
+ lines = []
55
+ IO.popen(command) { |f| lines = f.readlines }
56
+ return lines
57
+ end
58
+
59
+ def git_modified?(file)
60
+ return !run_command('git status').detect { |line| Regexp.new(Regexp.quote(file)) =~ line }.nil?
61
+ end
62
+
63
+ def git_commit_file(file, message, branch = nil)
64
+ verify_current_branch(branch) unless branch.nil?
65
+ if git_modified?(file)
66
+ sh "git add #{file}"
67
+ sh "git commit -m \"#{message}\""
68
+ else
69
+ raise "#{file} is not modified and cannot be committed!"
70
+ end
71
+ end
72
+
73
+ def git_create_tag(tag_name, message)
74
+ sh "git tag -a \"#{tag_name}\" -m \"#{message}\""
75
+ end
76
+
77
+ def git_push(remote = 'origin', branch = 'master', options = [])
78
+ verify_clean_status(branch)
79
+ options_str = options.map { |o| "--#{o}"}.join(' ')
80
+ sh "git push #{options_str} #{remote} #{branch}"
81
+ end
82
+
83
+ def gemspec_version=(new_version)
84
+ spec = File.read(gemspec_file)
85
+ spec.gsub!(/^(\s*s\.version\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{new_version}'#{$5}" }
86
+ spec.gsub!(/^(\s*s\.date\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{Date.today.strftime('%Y-%m-%d')}'#{$5}" }
87
+ File.open(gemspec_file, 'w') { |f| f << spec }
88
+ reload_gemspec!
89
+ end
90
+
91
+ def gemspec_date=(new_date)
92
+ spec = File.read(gemspec_file)
93
+ spec.gsub!(/^(\s*s\.date\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{new_date.strftime('%Y-%m-%d')}'#{$5}" }
94
+ File.open(gemspec_file, 'w') { |f| f << spec }
95
+ reload_gemspec!
96
+ end
97
+
98
+ def gemspec_file
99
+ @gemspec_file ||= Dir['*.gemspec'].first
100
+ end
101
+
102
+ def verify_current_branch(branch)
103
+ run_command('git branch').detect { |line| /^\* (.+)/ =~ line }
104
+ raise "You are currently not working in the master branch!" unless branch == $1
105
+ end
106
+
107
+ def verify_clean_status(on_branch = nil)
108
+ sh "git fetch"
109
+ lines = run_command('git status')
110
+ raise "You don't have the most recent version available. Run git pull first." if /^\# Your branch is behind/ =~ lines[1]
111
+ raise "You are currently not working in the #{on_branch} branch!" unless on_branch.nil? || (/^\# On branch (.+)/ =~ lines.first && $1 == on_branch)
112
+ raise "Your master branch contains modifications!" unless /^nothing to commit \(working directory clean\)/ =~ lines.last
113
+ end
114
+
115
+ def verify_version(new_version)
116
+ newest_version = run_command('git tag').map { |tag| tag.split(name + '-').last }.compact.map { |v| Gem::Version.new(v) }.max
117
+ raise "This version number (#{new_version}) is not higher than the highest tagged version (#{newest_version})" if !newest_version.nil? && newest_version >= Gem::Version.new(new_version.to_s)
118
+ end
119
+
120
+ def manifest_task
121
+ verify_current_branch('master')
122
+
123
+ list = Dir['**/*'].sort
124
+ list -= [gemspec_file]
125
+
126
+ if File.exist?('.gitignore')
127
+ File.read('.gitignore').each_line do |glob|
128
+ glob = glob.chomp.sub(/^\//, '')
129
+ list -= Dir[glob]
130
+ list -= Dir["#{glob}/**/*"] if File.directory?(glob) and !File.symlink?(glob)
131
+ end
132
+ end
133
+
134
+ # update the spec file
135
+ spec = File.read(gemspec_file)
136
+ spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
137
+ assignment = $1
138
+ bunch = $2 ? list.grep(/^test.*_test\.rb$/) : list
139
+ '%s%%w(%s)' % [assignment, bunch.join(' ')]
140
+ end
141
+
142
+ File.open(gemspec_file, 'w') { |f| f << spec }
143
+ reload_gemspec!
144
+ end
145
+
146
+ def build_task
147
+ sh "gem build #{gemspec_file}"
148
+ end
149
+
150
+ def install_task
151
+ raise "#{name} .gem file not found" unless File.exist?("#{name}-#{specification.version}.gem")
152
+ sh "gem install #{name}-#{specification.version}.gem"
153
+ end
154
+
155
+ def uninstall_task
156
+ raise "#{name} .gem file not found" unless File.exist?("#{name}-#{specification.version}.gem")
157
+ sh "gem uninstall #{name}"
158
+ end
159
+
160
+ def release_task
161
+ verify_clean_status('master')
162
+ verify_version(ENV['VERSION'] || @specification.version)
163
+
164
+ # update gemspec file
165
+ self.gemspec_version = ENV['VERSION'] if Gem::Version.correct?(ENV['VERSION'])
166
+ self.gemspec_date = Date.today
167
+ manifest_task
168
+ git_commit_file(gemspec_file, "Updated #{gemspec_file} for release of version #{@specification.version}") if git_modified?(gemspec_file)
169
+
170
+ # create tag and push changes
171
+ git_create_tag("#{@name}-#{@specification.version}", "Tagged version #{@specification.version}")
172
+ git_push('origin', 'master', [:tags])
173
+ end
174
+ end
175
+ end
176
+
177
+ Rake::GithubGem.define_tasks!
@@ -0,0 +1,10 @@
1
+ namespace :log do
2
+ desc "Analyze the Rails log file using the request-log-analyzer gem."
3
+ task :analyze => :environment do
4
+ puts "Analyzing the Rails log file using the request-log-analyzer gem."
5
+ puts "Environment: #{RAILS_ENV}"
6
+ puts "Logfile: #{Rails.configuration.log_path}"
7
+ puts ""
8
+ `request-log-analyzer #{Rails.configuration.log_path} -z`
9
+ end
10
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,6 @@
1
+ require 'spec/rake/spectask'
2
+
3
+ desc "Run all specs in spec directory (excluding plugin specs)"
4
+ Spec::Rake::SpecTask.new(:spec) do |t|
5
+ t.spec_files = FileList['spec/**/*_spec.rb']
6
+ end
@@ -0,0 +1,30 @@
1
+ require 'test/unit'
2
+
3
+ require "#{File.dirname(__FILE__)}/../lib/base/summarizer"
4
+
5
+ class BaseSummarizerTest < Test::Unit::TestCase
6
+
7
+ def test_compare_string_dates
8
+ summarizer = Base::Summarizer.new
9
+ assert_equal -1, summarizer.hamburger_compare_string_dates('2007-01-01 12:11:20', '2008-01-01 12:11:20')
10
+ assert_equal 1, summarizer.hamburger_compare_string_dates('2008-01-01 12:11:20', '2007-01-01 12:11:20')
11
+
12
+ assert_equal -1, summarizer.hamburger_compare_string_dates('2008-01-01 12:11:20', '2008-02-01 12:11:20')
13
+ assert_equal 1, summarizer.hamburger_compare_string_dates('2008-02-01 12:11:20', '2008-01-01 12:11:20')
14
+
15
+ assert_equal -1, summarizer.hamburger_compare_string_dates('2008-01-01 12:11:20', '2008-01-02 12:11:20')
16
+ assert_equal 1, summarizer.hamburger_compare_string_dates('2008-01-02 12:11:20', '2008-01-01 12:11:20')
17
+
18
+ assert_equal 0, summarizer.hamburger_compare_string_dates('2008-01-01 12:11:20', '2008-01-01 12:11:20')
19
+ assert_equal nil, summarizer.hamburger_compare_string_dates('2008-01-01 12:11:20', nil)
20
+ assert_equal nil, summarizer.hamburger_compare_string_dates(nil, '2008-01-01 12:11:20')
21
+ end
22
+
23
+ def test_has_timestamps
24
+ summarizer = Base::Summarizer.new
25
+ assert_equal false, !!summarizer.has_timestamps?
26
+ end
27
+
28
+
29
+
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wvanbergen-request-log-analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-12-11 00:00:00 -08:00
13
+ date: 2008-12-27 00:00:00 -08:00
14
14
  default_executable: request-log-analyzer
15
15
  dependencies: []
16
16
 
@@ -18,23 +18,19 @@ description: Rails log analyzer's purpose is to find what actions are best candi
18
18
  email: willem@vanbergen.org
19
19
  executables:
20
20
  - request-log-analyzer
21
- - request-log-database
22
21
  extensions: []
23
22
 
24
23
  extra_rdoc_files: []
25
24
 
26
25
  files:
27
26
  - LICENSE
28
- - README
27
+ - README.textile
29
28
  - Rakefile
30
29
  - TODO
31
30
  - bin
32
31
  - bin/request-log-analyzer
33
- - bin/request-log-database
34
32
  - lib
35
33
  - lib/base
36
- - lib/base/log_parser.rb
37
- - lib/base/record_inserter.rb
38
34
  - lib/base/summarizer.rb
39
35
  - lib/bashcolorizer.rb
40
36
  - lib/command_line
@@ -42,12 +38,24 @@ files:
42
38
  - lib/command_line/exceptions.rb
43
39
  - lib/command_line/flag.rb
44
40
  - lib/merb_analyzer
45
- - lib/merb_analyzer/log_parser.rb
46
41
  - lib/merb_analyzer/summarizer.rb
47
42
  - lib/rails_analyzer
48
- - lib/rails_analyzer/log_parser.rb
49
- - lib/rails_analyzer/record_inserter.rb
50
43
  - lib/rails_analyzer/summarizer.rb
44
+ - lib/rails_analyzer/virtual_mongrel.rb
45
+ - lib/request_log_analyzer
46
+ - lib/request_log_analyzer.rb
47
+ - lib/request_log_analyzer/aggregator
48
+ - lib/request_log_analyzer/aggregator/base.rb
49
+ - lib/request_log_analyzer/aggregator/database.rb
50
+ - lib/request_log_analyzer/aggregator/echo.rb
51
+ - lib/request_log_analyzer/aggregator/summarizer.rb
52
+ - lib/request_log_analyzer/controller.rb
53
+ - lib/request_log_analyzer/file_format
54
+ - lib/request_log_analyzer/file_format.rb
55
+ - lib/request_log_analyzer/file_format/merb.rb
56
+ - lib/request_log_analyzer/file_format/rails.rb
57
+ - lib/request_log_analyzer/log_parser.rb
58
+ - lib/request_log_analyzer/request.rb
51
59
  - lib/ruby-progressbar
52
60
  - lib/ruby-progressbar/progressbar.en.rd
53
61
  - lib/ruby-progressbar/progressbar.ja.rd
@@ -64,16 +72,34 @@ files:
64
72
  - output/total_db_time.rb
65
73
  - output/total_time.rb
66
74
  - output/usage.rb
75
+ - spec
76
+ - spec/controller_spec.rb
77
+ - spec/database_inserter_spec.rb
78
+ - spec/fixtures
79
+ - spec/fixtures/merb.log
80
+ - spec/fixtures/multiple_files_1.log
81
+ - spec/fixtures/multiple_files_2.log
82
+ - spec/fixtures/rails_1x.log
83
+ - spec/fixtures/rails_22.log
84
+ - spec/fixtures/rails_22_cached.log
85
+ - spec/fixtures/rails_unordered.log
86
+ - spec/fixtures/syslog_1x.log
87
+ - spec/fixtures/test_file_format.log
88
+ - spec/fixtures/test_language_combined.log
89
+ - spec/fixtures/test_order.log
90
+ - spec/line_definition_spec.rb
91
+ - spec/log_parser_spec.rb
92
+ - spec/merb_format_spec.rb
93
+ - spec/rails_format_spec.rb
94
+ - spec/request_spec.rb
95
+ - spec/spec_helper.rb
96
+ - spec/summarizer_spec.rb
97
+ - tasks
98
+ - tasks/github-gem.rake
99
+ - tasks/request_log_analyzer.rake
100
+ - tasks/rspec.rake
67
101
  - test
68
- - test/log_fragments
69
- - test/log_fragments/fragment_1.log
70
- - test/log_fragments/fragment_2.log
71
- - test/log_fragments/fragment_3.log
72
- - test/log_fragments/merb_1.log
73
- - test/merb_log_parser_test.rb
74
- - test/rails_log_parser_test.rb
75
- - test/record_inserter_test.rb
76
- - test/tasks.rake
102
+ - test/base_summarizer_test.rb
77
103
  has_rdoc: false
78
104
  homepage: http://github.com/wvanbergen/request-log-analyzer/wikis
79
105
  post_install_message:
@@ -101,6 +127,4 @@ signing_key:
101
127
  specification_version: 2
102
128
  summary: A command line tool to analyze Rails logs
103
129
  test_files:
104
- - test/merb_log_parser_test.rb
105
- - test/rails_log_parser_test.rb
106
- - test/record_inserter_test.rb
130
+ - test/base_summarizer_test.rb