wvanbergen-request-log-analyzer 0.3.4 → 1.0.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.
- data/README.textile +23 -10
- data/TODO +5 -0
- data/bin/request-log-analyzer +96 -20
- data/lib/request_log_analyzer.rb +14 -161
- data/spec/controller_spec.rb +13 -6
- data/spec/database_inserter_spec.rb +17 -14
- data/spec/line_definition_spec.rb +94 -4
- data/spec/log_parser_spec.rb +9 -11
- data/spec/merb_format_spec.rb +58 -58
- data/spec/rails_format_spec.rb +4 -4
- data/spec/request_spec.rb +6 -2
- data/spec/spec_helper.rb +22 -4
- data/spec/summarizer_spec.rb +0 -94
- data/tasks/github-gem.rake +1 -1
- data/test/rails_log_parser_test.rb +0 -5
- metadata +2 -2
- data/lib/base/summarizer.rb +0 -85
- data/lib/bashcolorizer.rb +0 -60
- data/lib/command_line/exceptions.rb +0 -37
- data/lib/merb_analyzer/summarizer.rb +0 -61
- data/lib/rails_analyzer/summarizer.rb +0 -81
- data/lib/rails_analyzer/virtual_mongrel.rb +0 -91
- data/lib/ruby-progressbar/progressbar.en.rd +0 -103
- data/lib/ruby-progressbar/progressbar.ja.rd +0 -100
- data/lib/ruby-progressbar/progressbar.rb +0 -236
- data/output/blockers.rb +0 -9
- data/output/errors.rb +0 -8
- data/output/hourly_spread.rb +0 -28
- data/output/mean_db_time.rb +0 -6
- data/output/mean_rendering_time.rb +0 -6
- data/output/mean_time.rb +0 -6
- data/output/most_requested.rb +0 -5
- data/output/timespan.rb +0 -18
- data/output/total_db_time.rb +0 -5
- data/output/total_time.rb +0 -5
- data/output/usage.rb +0 -16
- data/test/base_summarizer_test.rb +0 -30
data/spec/merb_format_spec.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe RequestLogAnalyzer::LogParser, "Merb without combined requests" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
describe RequestLogAnalyzer::LogParser, "Merb with combined requests" do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
1
|
+
# require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
#
|
3
|
+
# describe RequestLogAnalyzer::LogParser, "Merb without combined requests" do
|
4
|
+
# include RequestLogAnalyzerSpecHelper
|
5
|
+
#
|
6
|
+
# before(:each) do
|
7
|
+
# @log_parser = RequestLogAnalyzer::LogParser.new(:merb, :combined_requests => false)
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# it "should parse a stream and find valid requests" do
|
11
|
+
# File.open(log_fixture(:merb), 'r') do |io|
|
12
|
+
# @log_parser.parse_io(io) do |request|
|
13
|
+
# request.should be_kind_of(RequestLogAnalyzer::Request)
|
14
|
+
# request.should be_single_line
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# it "should find 33 request lines when lines are not linked" do
|
20
|
+
# @log_parser.should_receive(:handle_request).exactly(33).times
|
21
|
+
# @log_parser.parse_file(log_fixture(:merb))
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# it "should find 11 request start lines when lines are not linked" do
|
25
|
+
# @log_parser.should_receive(:handle_request).exactly(11).times
|
26
|
+
# @log_parser.parse_file(log_fixture(:merb), :line_types => [:started])
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
#
|
31
|
+
# describe RequestLogAnalyzer::LogParser, "Merb with combined requests" do
|
32
|
+
# include RequestLogAnalyzerSpecHelper
|
33
|
+
#
|
34
|
+
# before(:each) do
|
35
|
+
# @log_parser = RequestLogAnalyzer::LogParser.new(:merb, :combined_requests => true)
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# it "should have a valid language definitions" do
|
39
|
+
# @log_parser.file_format.should be_valid
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# it "should find 11 completed requests when lines are linked" do
|
43
|
+
# @log_parser.should_receive(:handle_request).exactly(11).times
|
44
|
+
# @log_parser.parse_file(log_fixture(:merb))
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# it "should parse all details from a request correctly" do
|
48
|
+
# request = nil
|
49
|
+
# @log_parser.parse_file(log_fixture(:merb)) { |found_request| request ||= found_request }
|
50
|
+
#
|
51
|
+
# request.should be_completed
|
52
|
+
# request[:timestamp].should == DateTime.parse('Fri Aug 29 11:10:23 +0200 2008')
|
53
|
+
# request[:dispatch_time].should == 0.243424
|
54
|
+
# request[:after_filters_time].should == 6.9e-05
|
55
|
+
# request[:before_filters_time].should == 0.213213
|
56
|
+
# request[:action_time].should == 0.241652
|
57
|
+
# end
|
58
|
+
# end
|
data/spec/rails_format_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe RequestLogAnalyzer::LogParser, "Rails without combined requests" do
|
|
4
4
|
include RequestLogAnalyzerSpecHelper
|
5
5
|
|
6
6
|
before(:each) do
|
7
|
-
@log_parser = RequestLogAnalyzer::LogParser.new(:rails, :combined_requests => false)
|
7
|
+
@log_parser = RequestLogAnalyzer::LogParser.new(RequestLogAnalyzer::FileFormat.load(:rails), :combined_requests => false)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should parse a stream and find valid requests" do
|
@@ -20,7 +20,7 @@ describe RequestLogAnalyzer::LogParser, "Rails without combined requests" do
|
|
20
20
|
@log_parser.parse_file(log_fixture(:rails_1x)) { |request| requests << request }
|
21
21
|
requests.length.should == 8
|
22
22
|
requests.each { |r| r.should be_single_line }
|
23
|
-
requests.select { |r| r.line_type == :
|
23
|
+
requests.select { |r| r.line_type == :processing }.should have(4).items
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -29,7 +29,7 @@ describe RequestLogAnalyzer::LogParser, "Rails with combined requests" do
|
|
29
29
|
include RequestLogAnalyzerSpecHelper
|
30
30
|
|
31
31
|
before(:each) do
|
32
|
-
@log_parser = RequestLogAnalyzer::LogParser.new(:rails, :combined_requests => true)
|
32
|
+
@log_parser = RequestLogAnalyzer::LogParser.new(RequestLogAnalyzer::FileFormat.load(:rails), :combined_requests => true)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should have a valid language definitions" do
|
@@ -45,7 +45,7 @@ describe RequestLogAnalyzer::LogParser, "Rails with combined requests" do
|
|
45
45
|
it "should parse a Rails 2.2 request properly" do
|
46
46
|
@log_parser.should_not_receive(:warn)
|
47
47
|
@log_parser.parse_file(log_fixture(:rails_22)) do |request|
|
48
|
-
request.should =~ :
|
48
|
+
request.should =~ :processing
|
49
49
|
request.should =~ :completed
|
50
50
|
|
51
51
|
request[:controller].should == 'PageController'
|
data/spec/request_spec.rb
CHANGED
@@ -2,8 +2,10 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
|
3
3
|
describe RequestLogAnalyzer::Request, :single_line do
|
4
4
|
|
5
|
+
include RequestLogAnalyzerSpecHelper
|
6
|
+
|
5
7
|
before(:each) do
|
6
|
-
@single_line_request = RequestLogAnalyzer::Request.new(
|
8
|
+
@single_line_request = RequestLogAnalyzer::Request.new(spec_format)
|
7
9
|
@single_line_request << { :line_type => :test, :lineno => 1, :test_capture => 'awesome!' }
|
8
10
|
end
|
9
11
|
|
@@ -38,8 +40,10 @@ end
|
|
38
40
|
|
39
41
|
describe RequestLogAnalyzer::Request, :combined do
|
40
42
|
|
43
|
+
include RequestLogAnalyzerSpecHelper
|
44
|
+
|
41
45
|
before(:each) do
|
42
|
-
@combined_request = RequestLogAnalyzer::Request.new(
|
46
|
+
@combined_request = RequestLogAnalyzer::Request.new(spec_format)
|
43
47
|
@combined_request << { :line_type => :first, :lineno => 1, :name => 'first line!' }
|
44
48
|
@combined_request << { :line_type => :test, :lineno => 4, :test_capture => 'testing' }
|
45
49
|
@combined_request << { :line_type => :test, :lineno => 7, :test_capture => 'testing some more' }
|
data/spec/spec_helper.rb
CHANGED
@@ -2,15 +2,33 @@ $: << File.join(File.dirname(__FILE__), '..', 'lib')
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'spec'
|
5
|
-
|
6
5
|
require 'request_log_analyzer'
|
7
6
|
|
8
7
|
module RequestLogAnalyzerSpecHelper
|
9
8
|
|
9
|
+
def format_file(format)
|
10
|
+
File.dirname(__FILE__) + "/file_formats/#{format}.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
def spec_format
|
14
|
+
@spec_format ||= begin
|
15
|
+
require format_file(:spec_format)
|
16
|
+
SpecFormat.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
10
20
|
def log_fixture(name)
|
11
21
|
File.dirname(__FILE__) + "/fixtures/#{name}.log"
|
12
22
|
end
|
13
23
|
|
24
|
+
def request(fields, format = TestFileFormat)
|
25
|
+
if fields.kind_of?(Array)
|
26
|
+
RequestLogAnalyzer::Request.create(format, *fields)
|
27
|
+
else
|
28
|
+
RequestLogAnalyzer::Request.create(format, fields)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
14
32
|
end
|
15
33
|
|
16
34
|
module TestFileFormat
|
@@ -32,18 +50,18 @@ module TestFileFormat
|
|
32
50
|
:header => true,
|
33
51
|
:teaser => /processing /,
|
34
52
|
:regexp => /processing request (\d+)/,
|
35
|
-
:captures => [{:request_no => :integer}]
|
53
|
+
:captures => [{ :name => :request_no, :type => :integer, :anonymize => :slightly }]
|
36
54
|
},
|
37
55
|
:test => {
|
38
56
|
:teaser => /testing /,
|
39
57
|
:regexp => /testing is (\w+)/,
|
40
|
-
:captures => [{:test_capture => :string}]
|
58
|
+
:captures => [{ :name => :test_capture, :type => :string, :anonymize => true}]
|
41
59
|
},
|
42
60
|
:last => {
|
43
61
|
:footer => true,
|
44
62
|
:teaser => /finishing /,
|
45
63
|
:regexp => /finishing request (\d+)/,
|
46
|
-
:captures => [{:request_no => :integer}]
|
64
|
+
:captures => [{ :name => :request_no, :type => :integer}]
|
47
65
|
}
|
48
66
|
}
|
49
67
|
end
|
data/spec/summarizer_spec.rb
CHANGED
@@ -4,106 +4,12 @@ require 'request_log_analyzer/aggregator/summarizer'
|
|
4
4
|
describe RequestLogAnalyzer::Aggregator::Summarizer, :single_line do
|
5
5
|
|
6
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
7
|
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
8
|
end
|
61
9
|
|
62
10
|
describe RequestLogAnalyzer::Aggregator::Summarizer, :combined_requests do
|
63
11
|
|
64
12
|
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
13
|
end
|
84
14
|
|
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
15
|
end
|
data/tasks/github-gem.rake
CHANGED
@@ -135,7 +135,7 @@ module Rake
|
|
135
135
|
spec = File.read(gemspec_file)
|
136
136
|
spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
|
137
137
|
assignment = $1
|
138
|
-
bunch = $2 ? list.grep(/^test.*_test\.rb$/) : list
|
138
|
+
bunch = $2 ? list.grep(/^(test.*_test\.rb|spec.*_spec.rb)$/) : list
|
139
139
|
'%s%%w(%s)' % [assignment, bunch.join(' ')]
|
140
140
|
end
|
141
141
|
|
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.
|
4
|
+
version: 1.0.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:
|
13
|
+
date: 2009-10-01 00:00:00 -07:00
|
14
14
|
default_executable: request-log-analyzer
|
15
15
|
dependencies: []
|
16
16
|
|
data/lib/base/summarizer.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
module Base
|
2
|
-
|
3
|
-
# Functions to summarize an array of requets.
|
4
|
-
# Can calculate request counts, duratations, mean times etc. of all the requests given.
|
5
|
-
class Summarizer
|
6
|
-
attr_reader :actions
|
7
|
-
attr_reader :errors
|
8
|
-
attr_reader :request_count
|
9
|
-
attr_reader :request_time_graph
|
10
|
-
attr_reader :first_request_at
|
11
|
-
attr_reader :last_request_at
|
12
|
-
attr_reader :methods
|
13
|
-
|
14
|
-
attr_accessor :blocker_duration
|
15
|
-
DEFAULT_BLOCKER_DURATION = 1.0
|
16
|
-
|
17
|
-
# Initializer. Sets global variables
|
18
|
-
# Options
|
19
|
-
def initialize(options = {})
|
20
|
-
@actions = {}
|
21
|
-
@blockers = {}
|
22
|
-
@errors = {}
|
23
|
-
@request_count = 0
|
24
|
-
@blocker_duration = DEFAULT_BLOCKER_DURATION
|
25
|
-
@request_time_graph = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
26
|
-
@methods = {:GET => 0, :POST => 0, :PUT => 0, :DELETE => 0, :unknown => 0}
|
27
|
-
|
28
|
-
self.initialize_hook(options) if self.respond_to?(:initialize_hook)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Check if any of the request parsed had a timestamp.
|
32
|
-
def has_timestamps?
|
33
|
-
@first_request_at
|
34
|
-
end
|
35
|
-
|
36
|
-
# Calculate the duration of a request
|
37
|
-
# Returns a DateTime object if possible, 0 otherwise.
|
38
|
-
def duration
|
39
|
-
(@last_request_at && @first_request_at) ? (DateTime.parse(@last_request_at) - DateTime.parse(@first_request_at)).ceil : 0
|
40
|
-
end
|
41
|
-
|
42
|
-
# Check if the request time graph usable data.
|
43
|
-
def request_time_graph?
|
44
|
-
@request_time_graph.uniq != [0] && duration > 0
|
45
|
-
end
|
46
|
-
|
47
|
-
# Return a list of requests sorted on a specific action field
|
48
|
-
# <tt>field</tt> The action field to sort by.
|
49
|
-
# <tt>min_count</tt> Values which fall below this amount are not returned (default nil).
|
50
|
-
def sort_actions_by(field, min_count = nil)
|
51
|
-
actions = min_count.nil? ? @actions.to_a : @actions.delete_if { |k, v| v[:count] < min_count}.to_a
|
52
|
-
actions.sort { |a, b| (a[1][field.to_sym] <=> b[1][field.to_sym]) }
|
53
|
-
end
|
54
|
-
|
55
|
-
# Returns a list of request blockers sorted by a specific field
|
56
|
-
# <tt>field</tt> The action field to sort by.
|
57
|
-
# <tt>min_count</tt> Values which fall below this amount are not returned (default @blocker_duration).
|
58
|
-
def sort_blockers_by(field, min_count = @blocker_duration)
|
59
|
-
blockers = min_count.nil? ? @blockers.to_a : @blockers.delete_if { |k, v| v[:count] < min_count}.to_a
|
60
|
-
blockers.sort { |a, b| a[1][field.to_sym] <=> b[1][field.to_sym] }
|
61
|
-
end
|
62
|
-
|
63
|
-
# Returns a list of request blockers sorted by a specific field
|
64
|
-
# <tt>field</tt> The action field to sort by.
|
65
|
-
# <tt>min_count</tt> Values which fall below this amount are not returned (default @blocker_duration).
|
66
|
-
def sort_errors_by(field, min_count = nil)
|
67
|
-
errors = min_count.nil? ? @errors.to_a : @errors.delete_if { |k, v| v[:count] < min_count}.to_a
|
68
|
-
errors.sort { |a, b| a[1][field.to_sym] <=> b[1][field.to_sym] }
|
69
|
-
end
|
70
|
-
|
71
|
-
# Compare date strings fast
|
72
|
-
# Assumes date formats: "2008-07-14 12:11:20" or alike.
|
73
|
-
# <tt>first_date</tt> The first date string
|
74
|
-
# <tt>second_date</tt> The second date string
|
75
|
-
# Returns -1 if first_date < second_date, nil if equal
|
76
|
-
# and 1 if first_date > second_date (<=>)
|
77
|
-
def hamburger_compare_string_dates first_date, second_date
|
78
|
-
return nil if first_date.nil? || second_date.nil?
|
79
|
-
|
80
|
-
first_date.gsub(/[^0-9|\s]/,'').to_i \
|
81
|
-
<=> \
|
82
|
-
second_date.gsub(/[^0-9|\s]/,'').to_i
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
data/lib/bashcolorizer.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
# Colorize a text output with the given color if.
|
2
|
-
# <tt>text</tt> The text to colorize.
|
3
|
-
# <tt>color_code</tt> The color code string to set
|
4
|
-
# <tt>color</tt> Does not color if false. Defaults to ($arguments && $arguments[:colorize])
|
5
|
-
def colorize(text, color_code, color = $colorize)
|
6
|
-
color ? "#{color_code}#{text}\e[0m" : text
|
7
|
-
end
|
8
|
-
|
9
|
-
# Draw a red line of text
|
10
|
-
def red(text)
|
11
|
-
colorize(text, "\e[31m")
|
12
|
-
end
|
13
|
-
|
14
|
-
# Draw a Green line of text
|
15
|
-
def green(text)
|
16
|
-
colorize(text, "\e[32m")
|
17
|
-
end
|
18
|
-
|
19
|
-
# Draw a Yellow line of text
|
20
|
-
def yellow(text)
|
21
|
-
colorize(text, "\e[33m")
|
22
|
-
end
|
23
|
-
|
24
|
-
# Draw a Yellow line of text
|
25
|
-
def blue(text)
|
26
|
-
colorize(text, "\e[34m")
|
27
|
-
end
|
28
|
-
|
29
|
-
def white(text)
|
30
|
-
colorize(text, "\e[37m")
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
#STYLE = {
|
35
|
-
# :default => “33[0m”,
|
36
|
-
# # styles
|
37
|
-
# :bold => “33[1m”,
|
38
|
-
# :underline => “33[4m”,
|
39
|
-
# :blink => “33[5m”,
|
40
|
-
# :reverse => “33[7m”,
|
41
|
-
# :concealed => “33[8m”,
|
42
|
-
# # font colors
|
43
|
-
# :black => “33[30m”,
|
44
|
-
# :red => “33[31m”,
|
45
|
-
# :green => “33[32m”,
|
46
|
-
# :yellow => “33[33m”,
|
47
|
-
# :blue => “33[34m”,
|
48
|
-
# :magenta => “33[35m”,
|
49
|
-
# :cyan => “33[36m”,
|
50
|
-
# :white => “33[37m”,
|
51
|
-
# # background colors
|
52
|
-
# :on_black => “33[40m”,
|
53
|
-
# :on_red => “33[41m”,
|
54
|
-
# :on_green => “33[42m”,
|
55
|
-
# :on_yellow => “33[43m”,
|
56
|
-
# :on_blue => “33[44m”,
|
57
|
-
# :on_magenta => “33[45m”,
|
58
|
-
# :on_cyan => “33[46m”,
|
59
|
-
# :on_white => “33[47m” }
|
60
|
-
#
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module CommandLine
|
2
|
-
|
3
|
-
# Commandline parsing errors and exceptions
|
4
|
-
class Error < Exception
|
5
|
-
end
|
6
|
-
|
7
|
-
# Missing a required flag
|
8
|
-
class FlagMissing < CommandLine::Error
|
9
|
-
end
|
10
|
-
|
11
|
-
# Missing a required file
|
12
|
-
class FileMissing < CommandLine::Error
|
13
|
-
end
|
14
|
-
|
15
|
-
# Missing a required flag argument
|
16
|
-
class FlagExpectsArgument < CommandLine::Error
|
17
|
-
def initialize(flag)
|
18
|
-
super("#{flag} expects an argument!")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Missing a required command
|
23
|
-
class CommandMissing < CommandLine::Error
|
24
|
-
def initialize(msg = "A command is missing")
|
25
|
-
super(msg)
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
# Encountered an unkown flag
|
31
|
-
class UnknownFlag < CommandLine::Error
|
32
|
-
def initialize(flag)
|
33
|
-
super("#{flag} not recognized as a valid flag!")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'date'
|
2
|
-
module MerbAnalyzer
|
3
|
-
|
4
|
-
# Functions to summarize an array of requets.
|
5
|
-
# Can calculate request counts, duratations, mean times etc. of all the requests given.
|
6
|
-
class Summarizer < Base::Summarizer
|
7
|
-
|
8
|
-
# Initializer. Sets global variables
|
9
|
-
def initialize_hook(options = {})
|
10
|
-
@hash_cache = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
# Parse a request string into a hash containing all keys found in the string.
|
14
|
-
# Yields the hash found to the block operator.
|
15
|
-
# <tt>request</tt> The request string to parse.
|
16
|
-
# <tt>&block</tt> Block operator
|
17
|
-
def group(request, &block)
|
18
|
-
request[:duration] ||= 0
|
19
|
-
|
20
|
-
case request[:type]
|
21
|
-
when :started
|
22
|
-
@first_request_at ||= request[:timestamp] # assume time-based order of file
|
23
|
-
@last_request_at = request[:timestamp] # assume time-based order of file
|
24
|
-
@request_time_graph[request[:timestamp][11..12].to_i] +=1
|
25
|
-
|
26
|
-
when :params
|
27
|
-
params_hash = {}
|
28
|
-
request[:raw_hash].split(',').collect{|x| x.split('=>')}.each do |k,v|
|
29
|
-
key = k.gsub('"', '').gsub(' ', '').to_sym
|
30
|
-
value = v.gsub('"', '')
|
31
|
-
request.store(key, value)
|
32
|
-
end
|
33
|
-
|
34
|
-
hash = block_given? ? yield(request) : request.hash
|
35
|
-
|
36
|
-
@actions[hash] ||= {:count => 0, :total_time => 0.0, :total_db_time => 0.0, :total_rendering_time => 0.0,
|
37
|
-
:min_time => request[:duration], :max_time => request[:duration] }
|
38
|
-
|
39
|
-
@actions[hash][:count] += 1
|
40
|
-
request[:method] = 'GET' unless request[:method]
|
41
|
-
@methods[request[:method].upcase.to_sym] += 1
|
42
|
-
|
43
|
-
@hash_cache = hash
|
44
|
-
when :completed
|
45
|
-
@request_count += 1
|
46
|
-
|
47
|
-
@actions[@hash_cache][:total_time] += request[:dispatch_time]
|
48
|
-
@actions[@hash_cache][:mean_time] = @actions[@hash_cache][:total_time] / @actions[@hash_cache][:count].to_f
|
49
|
-
@actions[@hash_cache][:min_time] = [@actions[@hash_cache][:min_time], request[:dispatch_time]].min
|
50
|
-
@actions[@hash_cache][:max_time] = [@actions[@hash_cache][:min_time], request[:dispatch_time]].max
|
51
|
-
|
52
|
-
@actions[@hash_cache][:total_db_time] = 0
|
53
|
-
@actions[@hash_cache][:mean_db_time] = 0
|
54
|
-
@actions[@hash_cache][:mean_rendering_time] = 0
|
55
|
-
|
56
|
-
when :failed
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|