request-log-analyzer 1.3.7 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +3 -3
- data/README.rdoc +1 -1
- data/bin/request-log-analyzer +17 -14
- data/lib/cli/command_line_arguments.rb +51 -51
- data/lib/cli/database_console.rb +3 -3
- data/lib/cli/database_console_init.rb +2 -2
- data/lib/cli/progressbar.rb +10 -10
- data/lib/cli/tools.rb +3 -3
- data/lib/request_log_analyzer.rb +4 -4
- data/lib/request_log_analyzer/aggregator.rb +10 -10
- data/lib/request_log_analyzer/aggregator/database_inserter.rb +9 -9
- data/lib/request_log_analyzer/aggregator/echo.rb +14 -9
- data/lib/request_log_analyzer/aggregator/summarizer.rb +26 -26
- data/lib/request_log_analyzer/controller.rb +153 -69
- data/lib/request_log_analyzer/database.rb +13 -13
- data/lib/request_log_analyzer/database/base.rb +17 -17
- data/lib/request_log_analyzer/database/connection.rb +3 -3
- data/lib/request_log_analyzer/database/request.rb +2 -2
- data/lib/request_log_analyzer/database/source.rb +1 -1
- data/lib/request_log_analyzer/file_format.rb +15 -15
- data/lib/request_log_analyzer/file_format/amazon_s3.rb +16 -16
- data/lib/request_log_analyzer/file_format/apache.rb +20 -19
- data/lib/request_log_analyzer/file_format/merb.rb +12 -12
- data/lib/request_log_analyzer/file_format/rack.rb +4 -4
- data/lib/request_log_analyzer/file_format/rails.rb +146 -70
- data/lib/request_log_analyzer/file_format/rails_development.rb +4 -49
- data/lib/request_log_analyzer/filter.rb +6 -6
- data/lib/request_log_analyzer/filter/anonymize.rb +6 -6
- data/lib/request_log_analyzer/filter/field.rb +9 -9
- data/lib/request_log_analyzer/filter/timespan.rb +12 -10
- data/lib/request_log_analyzer/line_definition.rb +15 -14
- data/lib/request_log_analyzer/log_processor.rb +22 -22
- data/lib/request_log_analyzer/mailer.rb +15 -9
- data/lib/request_log_analyzer/output.rb +53 -12
- data/lib/request_log_analyzer/output/fixed_width.rb +40 -41
- data/lib/request_log_analyzer/output/html.rb +20 -20
- data/lib/request_log_analyzer/request.rb +35 -36
- data/lib/request_log_analyzer/source.rb +7 -7
- data/lib/request_log_analyzer/source/database_loader.rb +7 -7
- data/lib/request_log_analyzer/source/log_parser.rb +48 -43
- data/lib/request_log_analyzer/tracker.rb +128 -14
- data/lib/request_log_analyzer/tracker/duration.rb +39 -132
- data/lib/request_log_analyzer/tracker/frequency.rb +31 -32
- data/lib/request_log_analyzer/tracker/hourly_spread.rb +20 -19
- data/lib/request_log_analyzer/tracker/timespan.rb +17 -17
- data/lib/request_log_analyzer/tracker/traffic.rb +36 -116
- data/request-log-analyzer.gemspec +19 -15
- data/spec/fixtures/rails_22.log +1 -1
- data/spec/integration/command_line_usage_spec.rb +1 -1
- data/spec/lib/helpers.rb +7 -7
- data/spec/lib/macros.rb +3 -3
- data/spec/lib/matchers.rb +41 -27
- data/spec/lib/mocks.rb +15 -14
- data/spec/lib/testing_format.rb +9 -9
- data/spec/spec_helper.rb +6 -6
- data/spec/unit/aggregator/database_inserter_spec.rb +13 -13
- data/spec/unit/aggregator/summarizer_spec.rb +4 -4
- data/spec/unit/controller/controller_spec.rb +2 -2
- data/spec/unit/controller/log_processor_spec.rb +1 -1
- data/spec/unit/database/base_class_spec.rb +19 -19
- data/spec/unit/database/connection_spec.rb +3 -3
- data/spec/unit/database/database_spec.rb +25 -25
- data/spec/unit/file_format/amazon_s3_format_spec.rb +5 -5
- data/spec/unit/file_format/apache_format_spec.rb +13 -13
- data/spec/unit/file_format/file_format_api_spec.rb +13 -13
- data/spec/unit/file_format/line_definition_spec.rb +24 -17
- data/spec/unit/file_format/merb_format_spec.rb +41 -45
- data/spec/unit/file_format/rails_format_spec.rb +157 -117
- data/spec/unit/filter/anonymize_filter_spec.rb +2 -2
- data/spec/unit/filter/field_filter_spec.rb +13 -13
- data/spec/unit/filter/filter_spec.rb +1 -1
- data/spec/unit/filter/timespan_filter_spec.rb +15 -15
- data/spec/unit/mailer_spec.rb +30 -0
- data/spec/unit/{source/request_spec.rb → request_spec.rb} +30 -30
- data/spec/unit/source/log_parser_spec.rb +27 -27
- data/spec/unit/tracker/duration_tracker_spec.rb +115 -78
- data/spec/unit/tracker/frequency_tracker_spec.rb +74 -63
- data/spec/unit/tracker/hourly_spread_spec.rb +28 -20
- data/spec/unit/tracker/timespan_tracker_spec.rb +25 -13
- data/spec/unit/tracker/tracker_api_spec.rb +13 -13
- data/spec/unit/tracker/traffic_tracker_spec.rb +81 -79
- data/tasks/github-gem.rake +125 -75
- data/tasks/request_log_analyzer.rake +2 -2
- metadata +8 -6
@@ -1,93 +1,130 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
|
3
|
-
describe RequestLogAnalyzer::Tracker::Duration
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@tracker = RequestLogAnalyzer::Tracker::Duration.new(:duration => :duration, :category => :category)
|
7
|
-
@tracker.prepare
|
8
|
-
end
|
3
|
+
describe RequestLogAnalyzer::Tracker::Duration do
|
9
4
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
5
|
+
context 'using a static category' do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@tracker = RequestLogAnalyzer::Tracker::Duration.new(:duration => :duration, :category => :category)
|
9
|
+
@tracker.prepare
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should create a category for every request using the category field" do
|
13
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
14
|
+
@tracker.categories.keys.should include('a')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should register a request as hit in the right category" do
|
18
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
19
|
+
@tracker.update(request(:category => 'b', :duration => 0.3))
|
20
|
+
@tracker.update(request(:category => 'b', :duration => 0.4))
|
21
|
+
|
22
|
+
@tracker.hits('a').should == 1
|
23
|
+
@tracker.hits('b').should == 2
|
24
|
+
end
|
22
25
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
|
27
|
+
context 'using a dynamic category' do
|
28
|
+
before(:each) do
|
29
|
+
@categorizer = Proc.new { |request| request[:duration] > 0.2 ? 'slow' : 'fast' }
|
30
|
+
@tracker = RequestLogAnalyzer::Tracker::Duration.new(:duration => :duration, :category => @categorizer)
|
31
|
+
@tracker.prepare
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should use the categorizer to determine the right category" do
|
35
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
36
|
+
@tracker.update(request(:category => 'b', :duration => 0.3))
|
37
|
+
@tracker.update(request(:category => 'b', :duration => 0.4))
|
38
|
+
|
39
|
+
@tracker.hits('fast').should == 1
|
40
|
+
@tracker.hits('slow').should == 2
|
41
|
+
end
|
31
42
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
43
|
+
|
44
|
+
describe '#update' do
|
45
|
+
|
46
|
+
before(:each) do
|
47
|
+
@tracker = RequestLogAnalyzer::Tracker::Duration.new(:duration => :duration, :category => :category)
|
48
|
+
@tracker.prepare
|
49
|
+
|
50
|
+
@tracker.update(request(:category => 'a', :duration => 0.4))
|
51
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
52
|
+
@tracker.update(request(:category => 'a', :duration => 0.3))
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should sum of the durations for a category correctly" do
|
56
|
+
@tracker.sum('a').should be_close(0.9, 0.000001)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should overall sum of the durations correctly" do
|
60
|
+
@tracker.sum_overall.should be_close(0.9, 0.000001)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should keep track of the minimum and maximum duration" do
|
64
|
+
@tracker.min('a').should == 0.2
|
65
|
+
@tracker.max('a').should == 0.4
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should calculate the mean duration correctly" do
|
69
|
+
@tracker.mean('a').should be_close(0.3, 0.000001)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should calculate the overall mean duration correctly" do
|
73
|
+
@tracker.mean_overall.should be_close(0.3, 0.000001)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should calculate the duration variance correctly" do
|
77
|
+
@tracker.variance('a').should be_close(0.01, 0.000001)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should calculate the duration standard deviation correctly" do
|
81
|
+
@tracker.stddev('a').should be_close(0.1, 0.000001)
|
82
|
+
end
|
40
83
|
end
|
41
|
-
|
42
|
-
it "should set min and max duration correctly" do
|
43
|
-
@tracker.update(request(:category => 'a', :duration => 0.2))
|
44
|
-
@tracker.update(request(:category => 'b', :duration => 0.3))
|
45
|
-
@tracker.update(request(:category => 'b', :duration => 0.4))
|
46
|
-
|
47
|
-
@tracker.min_duration('b').should == 0.3
|
48
|
-
@tracker.max_duration('b').should == 0.4
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
84
|
|
53
|
-
describe
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
85
|
+
describe '#report' do
|
86
|
+
|
87
|
+
before(:each) do
|
88
|
+
@tracker = RequestLogAnalyzer::Tracker::Duration.new(:category => :category, :duration => :duration)
|
89
|
+
@tracker.prepare
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should generate a report without errors when one category is present" do
|
93
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
94
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should generate a report without errors when no category is present" do
|
98
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should generate a report without errors when multiple categories are present" do
|
102
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
103
|
+
@tracker.update(request(:category => 'b', :duration => 0.2))
|
104
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should generate a YAML output" do
|
108
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
109
|
+
@tracker.update(request(:category => 'b', :duration => 0.2))
|
110
|
+
@tracker.to_yaml_object.should == {"a"=>{:hits=>1, :min=>0.2, :mean=>0.2, :max=>0.2, :sum_of_squares=>0.0, :sum=>0.2}, "b"=>{:hits=>1, :min=>0.2, :mean=>0.2, :max=>0.2, :sum_of_squares=>0.0, :sum=>0.2}}
|
111
|
+
end
|
59
112
|
end
|
60
113
|
|
61
|
-
|
62
|
-
@tracker.
|
63
|
-
@tracker.update(request(:category => 'b', :duration => 0.3))
|
64
|
-
@tracker.update(request(:category => 'b', :duration => 0.4))
|
114
|
+
describe '#display_value' do
|
115
|
+
before(:each) { @tracker = RequestLogAnalyzer::Tracker::Duration.new(:category => :category, :duration => :duration) }
|
65
116
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
117
|
+
it "should only display seconds when time < 60" do
|
118
|
+
@tracker.display_value(33.12).should == '33.12s'
|
119
|
+
end
|
71
120
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
@tracker = RequestLogAnalyzer::Tracker::Duration.new(:category => :category, :duration => :duration)
|
76
|
-
@tracker.prepare
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should generate a report without errors when one category is present" do
|
80
|
-
@tracker.update(request(:category => 'a', :duration => 0.2))
|
81
|
-
lambda { @tracker.report(mock_output) }.should_not raise_error
|
82
|
-
end
|
121
|
+
it "should display minutes and wholeseconds when time > 60" do
|
122
|
+
@tracker.display_value(63.12).should == '1m03s'
|
123
|
+
end
|
83
124
|
|
84
|
-
|
85
|
-
|
86
|
-
|
125
|
+
it "should display minutes and wholeseconds when time > 60" do
|
126
|
+
@tracker.display_value(3601.12).should == '1h00m01s'
|
127
|
+
end
|
87
128
|
|
88
|
-
it "should generate a report without errors when multiple categories are present" do
|
89
|
-
@tracker.update(request(:category => 'a', :duration => 0.2))
|
90
|
-
@tracker.update(request(:category => 'b', :duration => 0.2))
|
91
|
-
lambda { @tracker.report(mock_output) }.should_not raise_error
|
92
129
|
end
|
93
130
|
end
|
@@ -1,77 +1,88 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
|
3
|
-
describe RequestLogAnalyzer::Tracker::Frequency
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:category => :category)
|
7
|
-
@tracker.prepare
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
it "should register a request in the right category" do
|
12
|
-
@tracker.update(request(:category => 'a', :blah => 0.2))
|
13
|
-
@tracker.frequencies.keys.should include('a')
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should register a request in the right category" do
|
17
|
-
@tracker.update(request(:category => 'a', :blah => 0.2))
|
18
|
-
@tracker.update(request(:category => 'b', :blah => 0.2))
|
19
|
-
@tracker.update(request(:category => 'b', :blah => 0.2))
|
20
|
-
|
21
|
-
@tracker.frequency('a').should == 1
|
22
|
-
@tracker.frequency('b').should == 2
|
23
|
-
@tracker.overall_frequency.should == 3
|
24
|
-
end
|
3
|
+
describe RequestLogAnalyzer::Tracker::Frequency do
|
25
4
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
5
|
+
context 'static category' do
|
6
|
+
before(:each) do
|
7
|
+
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:category => :category)
|
8
|
+
@tracker.prepare
|
9
|
+
end
|
30
10
|
|
31
|
-
|
32
|
-
|
33
|
-
|
11
|
+
it "should register a request in the right category" do
|
12
|
+
@tracker.update(request(:category => 'a', :blah => 0.2))
|
13
|
+
@tracker.categories.should include('a')
|
14
|
+
end
|
34
15
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:category => @categorizer)
|
40
|
-
@tracker.prepare
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should use the categorizer to determine the right category" do
|
44
|
-
@tracker.update(request(:category => 'a', :duration => 0.2))
|
45
|
-
@tracker.update(request(:category => 'b', :duration => 0.3))
|
46
|
-
@tracker.update(request(:category => 'b', :duration => 0.4))
|
47
|
-
|
48
|
-
@tracker.frequency('fast').should == 1
|
49
|
-
@tracker.frequency('slow').should == 2
|
50
|
-
@tracker.frequency('moderate').should == 0
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
16
|
+
it "should register a request in the right category" do
|
17
|
+
@tracker.update(request(:category => 'a', :blah => 0.2))
|
18
|
+
@tracker.update(request(:category => 'b', :blah => 0.2))
|
19
|
+
@tracker.update(request(:category => 'b', :blah => 0.2))
|
54
20
|
|
21
|
+
@tracker.frequency('a').should == 1
|
22
|
+
@tracker.frequency('b').should == 2
|
23
|
+
@tracker.overall_frequency.should == 3
|
24
|
+
end
|
55
25
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
26
|
+
it "should sort correctly by frequency" do
|
27
|
+
@tracker.update(request(:category => 'a', :blah => 0.2))
|
28
|
+
@tracker.update(request(:category => 'b', :blah => 0.2))
|
29
|
+
@tracker.update(request(:category => 'b', :blah => 0.2))
|
30
|
+
|
31
|
+
@tracker.sorted_by_frequency.should == [['b', 2], ['a', 1]]
|
32
|
+
end
|
61
33
|
end
|
62
34
|
|
63
|
-
|
64
|
-
|
65
|
-
|
35
|
+
|
36
|
+
context 'dynamic category' do
|
37
|
+
before(:each) do
|
38
|
+
@categorizer = Proc.new { |request| request[:duration] > 0.2 ? 'slow' : 'fast' }
|
39
|
+
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:category => @categorizer)
|
40
|
+
@tracker.prepare
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should use the categorizer to determine the right category" do
|
44
|
+
@tracker.update(request(:category => 'a', :duration => 0.2))
|
45
|
+
@tracker.update(request(:category => 'b', :duration => 0.3))
|
46
|
+
@tracker.update(request(:category => 'b', :duration => 0.4))
|
47
|
+
|
48
|
+
@tracker.frequency('fast').should == 1
|
49
|
+
@tracker.frequency('slow').should == 2
|
50
|
+
@tracker.frequency('moderate').should == 0
|
51
|
+
end
|
66
52
|
end
|
67
53
|
|
68
|
-
|
69
|
-
|
54
|
+
describe '#report' do
|
55
|
+
before(:each) do
|
56
|
+
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:category => :category)
|
57
|
+
@tracker.prepare
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should generate a report without errors when one category is present" do
|
61
|
+
@tracker.update(request(:category => 'a', :blah => 0.2))
|
62
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should generate a report without errors when no category is present" do
|
66
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should generate a report without errors when multiple categories are present" do
|
70
|
+
@tracker.update(request(:category => 'a', :blah => 0.2))
|
71
|
+
@tracker.update(request(:category => 'b', :blah => 0.2))
|
72
|
+
lambda { @tracker.report(mock_output) }.should_not raise_error
|
73
|
+
end
|
70
74
|
end
|
71
75
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
+
describe '#to_yaml_object' do
|
77
|
+
before(:each) do
|
78
|
+
@tracker = RequestLogAnalyzer::Tracker::Frequency.new(:category => :category)
|
79
|
+
@tracker.prepare
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should generate a YAML output" do
|
83
|
+
@tracker.update(request(:category => 'a', :blah => 0.2))
|
84
|
+
@tracker.update(request(:category => 'b', :blah => 0.2))
|
85
|
+
@tracker.to_yaml_object.should == { "a" => 1, "b" => 1 }
|
86
|
+
end
|
76
87
|
end
|
77
|
-
end
|
88
|
+
end
|
@@ -9,49 +9,49 @@ describe RequestLogAnalyzer::Tracker::HourlySpread do
|
|
9
9
|
|
10
10
|
it "should store timestamps correctly" do
|
11
11
|
@tracker.update(request(:timestamp => 20090102000000))
|
12
|
-
@tracker.update(request(:timestamp => 20090101000000))
|
13
|
-
@tracker.update(request(:timestamp => 20090103000000))
|
14
|
-
|
15
|
-
@tracker.
|
12
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
13
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
14
|
+
|
15
|
+
@tracker.hour_frequencies[0].should eql(3)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should count the number of timestamps correctly" do
|
19
19
|
@tracker.update(request(:timestamp => 20090102000000))
|
20
|
-
@tracker.update(request(:timestamp => 20090101000000))
|
21
|
-
@tracker.update(request(:timestamp => 20090103000000))
|
22
|
-
@tracker.update(request(:timestamp => 20090103010000))
|
23
|
-
|
20
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
21
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
22
|
+
@tracker.update(request(:timestamp => 20090103010000))
|
23
|
+
|
24
24
|
@tracker.total_requests.should eql(4)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should set the first request timestamp correctly" do
|
28
28
|
@tracker.update(request(:timestamp => 20090102000000))
|
29
|
-
@tracker.update(request(:timestamp => 20090101000000))
|
30
|
-
@tracker.update(request(:timestamp => 20090103000000))
|
31
|
-
|
29
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
30
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
31
|
+
|
32
32
|
@tracker.first_timestamp.should == DateTime.parse('Januari 1, 2009 00:00:00')
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should set the last request timestamp correctly" do
|
36
36
|
@tracker.update(request(:timestamp => 20090102000000))
|
37
|
-
@tracker.update(request(:timestamp => 20090101000000))
|
38
|
-
@tracker.update(request(:timestamp => 20090103000000))
|
37
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
38
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
39
39
|
|
40
40
|
@tracker.last_timestamp.should == DateTime.parse('Januari 3, 2009 00:00:00')
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should return the correct timespan in days when multiple requests are given" do
|
44
44
|
@tracker.update(request(:timestamp => 20090102000000))
|
45
|
-
@tracker.update(request(:timestamp => 20090101000000))
|
46
|
-
@tracker.update(request(:timestamp => 20090103000000))
|
47
|
-
|
48
|
-
@tracker.timespan.should == 2
|
45
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
46
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
47
|
+
|
48
|
+
@tracker.timespan.should == 2
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
52
52
|
|
53
53
|
describe RequestLogAnalyzer::Tracker::HourlySpread, 'reporting' do
|
54
|
-
|
54
|
+
|
55
55
|
before(:each) do
|
56
56
|
@tracker = RequestLogAnalyzer::Tracker::HourlySpread.new
|
57
57
|
@tracker.prepare
|
@@ -63,9 +63,17 @@ describe RequestLogAnalyzer::Tracker::HourlySpread, 'reporting' do
|
|
63
63
|
|
64
64
|
it "should generate a report without errors when multiple requests were tracked" do
|
65
65
|
@tracker.update(request(:timestamp => 20090102000000))
|
66
|
-
@tracker.update(request(:timestamp => 20090101000000))
|
67
|
-
@tracker.update(request(:timestamp => 20090103000000))
|
66
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
67
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
68
68
|
@tracker.update(request(:timestamp => 20090103010000))
|
69
69
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
70
70
|
end
|
71
|
+
|
72
|
+
it "should generate a YAML output" do
|
73
|
+
@tracker.update(request(:timestamp => 20090102000000))
|
74
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
75
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
76
|
+
@tracker.update(request(:timestamp => 20090103010000))
|
77
|
+
@tracker.to_yaml_object.should == {"22:00 - 23:00"=>0, "9:00 - 10:00"=>0, "7:00 - 8:00"=>0, "2:00 - 3:00"=>0, "12:00 - 13:00"=>0, "11:00 - 12:00"=>0, "16:00 - 17:00"=>0, "15:00 - 16:00"=>0, "19:00 - 20:00"=>0, "3:00 - 4:00"=>0, "21:00 - 22:00"=>0, "20:00 - 21:00"=>0, "14:00 - 15:00"=>0, "13:00 - 14:00"=>0, "4:00 - 5:00"=>0, "10:00 - 11:00"=>0, "18:00 - 19:00"=>0, "17:00 - 18:00"=>0, "8:00 - 9:00"=>0, "6:00 - 7:00"=>0, "5:00 - 6:00"=>0, "1:00 - 2:00"=>1, "0:00 - 1:00"=>3, "23:00 - 24:00"=>0}
|
78
|
+
end
|
71
79
|
end
|
@@ -9,30 +9,30 @@ describe RequestLogAnalyzer::Tracker::Timespan do
|
|
9
9
|
|
10
10
|
it "should set the first request timestamp correctly" do
|
11
11
|
@tracker.update(request(:timestamp => 20090102000000))
|
12
|
-
@tracker.update(request(:timestamp => 20090101000000))
|
13
|
-
@tracker.update(request(:timestamp => 20090103000000))
|
14
|
-
|
12
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
13
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
14
|
+
|
15
15
|
@tracker.first_timestamp.should == DateTime.parse('Januari 1, 2009 00:00:00')
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should set the last request timestamp correctly" do
|
19
19
|
@tracker.update(request(:timestamp => 20090102000000))
|
20
|
-
@tracker.update(request(:timestamp => 20090101000000))
|
21
|
-
@tracker.update(request(:timestamp => 20090103000000))
|
20
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
21
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
22
22
|
|
23
23
|
@tracker.last_timestamp.should == DateTime.parse('Januari 3, 2009 00:00:00')
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should return the correct timespan in days when multiple requests are given" do
|
27
27
|
@tracker.update(request(:timestamp => 20090102000000))
|
28
|
-
@tracker.update(request(:timestamp => 20090101000000))
|
29
|
-
@tracker.update(request(:timestamp => 20090103000000))
|
30
|
-
|
31
|
-
@tracker.timespan.should == 2
|
28
|
+
@tracker.update(request(:timestamp => 20090101000000))
|
29
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
30
|
+
|
31
|
+
@tracker.timespan.should == 2
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should return a timespan of 0 days when only one timestamp is set" do
|
35
|
-
@tracker.update(request(:timestamp => 20090103000000))
|
35
|
+
@tracker.update(request(:timestamp => 20090103000000))
|
36
36
|
@tracker.timespan.should == 0
|
37
37
|
end
|
38
38
|
|
@@ -42,11 +42,15 @@ describe RequestLogAnalyzer::Tracker::Timespan do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
describe RequestLogAnalyzer::Tracker::Timespan, 'reporting' do
|
45
|
-
|
45
|
+
|
46
46
|
before(:each) do
|
47
47
|
@tracker = RequestLogAnalyzer::Tracker::Timespan.new
|
48
48
|
@tracker.prepare
|
49
49
|
end
|
50
|
+
|
51
|
+
it "should have a title" do
|
52
|
+
@tracker.title.should_not eql("")
|
53
|
+
end
|
50
54
|
|
51
55
|
it "should generate a report without errors when no request was tracked" do
|
52
56
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
@@ -55,7 +59,15 @@ describe RequestLogAnalyzer::Tracker::Timespan, 'reporting' do
|
|
55
59
|
it "should generate a report without errors when multiple requests were tracked" do
|
56
60
|
@tracker.update(request(:category => 'a', :timestamp => 20090102000000))
|
57
61
|
@tracker.update(request(:category => 'a', :timestamp => 20090101000000))
|
58
|
-
@tracker.update(request(:category => 'a', :timestamp => 20090103000000))
|
62
|
+
@tracker.update(request(:category => 'a', :timestamp => 20090103000000))
|
59
63
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
60
64
|
end
|
65
|
+
|
66
|
+
it "should generate a YAML output" do
|
67
|
+
@tracker.update(request(:category => 'a', :timestamp => 20090102000000))
|
68
|
+
@tracker.update(request(:category => 'a', :timestamp => 20090101000000))
|
69
|
+
@tracker.update(request(:category => 'a', :timestamp => 20090103000000))
|
70
|
+
@tracker.to_yaml_object.should == { :first => DateTime.parse('20090101000000'), :last => DateTime.parse('20090103000000')}
|
71
|
+
end
|
72
|
+
|
61
73
|
end
|