request-log-analyzer 1.1.4 → 1.1.5.1
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/lib/request_log_analyzer/aggregator/database.rb +19 -5
- data/lib/request_log_analyzer/line_definition.rb +5 -6
- data/lib/request_log_analyzer/request.rb +3 -1
- data/lib/request_log_analyzer/source/database.rb +76 -0
- data/lib/request_log_analyzer/tracker/duration.rb +1 -1
- data/lib/request_log_analyzer/tracker/hourly_spread.rb +2 -3
- data/spec/unit/aggregator/database_inserter_spec.rb +1 -1
- data/spec/unit/file_format/line_definition_spec.rb +1 -1
- metadata +3 -2
@@ -96,6 +96,11 @@ module RequestLogAnalyzer::Aggregator
|
|
96
96
|
class_name = "#{name}_line".camelize
|
97
97
|
klass = Class.new(ActiveRecord::Base)
|
98
98
|
klass.send(:belongs_to, :request)
|
99
|
+
|
100
|
+
definition.captures.each do |capture|
|
101
|
+
klass.send(:serialize, capture[:name], Hash) if capture[:provides]
|
102
|
+
end
|
103
|
+
|
99
104
|
@orm_module.const_set(class_name, klass) unless @orm_module.const_defined?(class_name)
|
100
105
|
@request_class.send(:has_many, "#{name}_lines".to_sym)
|
101
106
|
end
|
@@ -148,11 +153,20 @@ module RequestLogAnalyzer::Aggregator
|
|
148
153
|
# TODO: make more robust / include in file-format definition
|
149
154
|
def column_type(type_indicator)
|
150
155
|
case type_indicator
|
151
|
-
when :eval;
|
152
|
-
when :
|
153
|
-
when :
|
154
|
-
when :
|
155
|
-
|
156
|
+
when :eval; :text
|
157
|
+
when :text; :text
|
158
|
+
when :string; :string
|
159
|
+
when :sec; :double
|
160
|
+
when :msec; :double
|
161
|
+
when :duration; :double
|
162
|
+
when :float; :double
|
163
|
+
when :double; :double
|
164
|
+
when :integer; :integer
|
165
|
+
when :int; :int
|
166
|
+
when :timestamp; :datetime
|
167
|
+
when :datetime; :datetime
|
168
|
+
when :date; :date
|
169
|
+
else :string
|
156
170
|
end
|
157
171
|
end
|
158
172
|
end
|
@@ -78,12 +78,11 @@ module RequestLogAnalyzer
|
|
78
78
|
value_hash = {}
|
79
79
|
captures.each_with_index do |capture, index|
|
80
80
|
converted = request.convert_value(values[index], capture)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
value_hash[capture[:name]] ||= converted
|
81
|
+
value_hash[capture[:name]] ||= converted
|
82
|
+
if converted.kind_of?(Hash) && capture[:provides].kind_of?(Hash)
|
83
|
+
capture[:provides].each do |name, type|
|
84
|
+
value_hash[name] ||= request.convert_value(converted[name], { :type => type })
|
85
|
+
end
|
87
86
|
end
|
88
87
|
end
|
89
88
|
return value_hash
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'activerecord'
|
3
|
+
|
4
|
+
module RequestLogAnalyzer::Source
|
5
|
+
|
6
|
+
# Active Resource hook
|
7
|
+
class CompletedLine < ActiveRecord::Base
|
8
|
+
def convert(file_format)
|
9
|
+
RequestLogAnalyzer::Request.create(file_format, self.attributes)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# The Database class gets log data from the database.
|
14
|
+
class Database < Base
|
15
|
+
|
16
|
+
attr_reader :source_files
|
17
|
+
attr_reader :requests
|
18
|
+
|
19
|
+
# Initializes the log file parser instance.
|
20
|
+
# It will apply the language specific FileFormat module to this instance. It will use the line
|
21
|
+
# definitions in this module to parse any input that it is given (see parse_io).
|
22
|
+
#
|
23
|
+
# <tt>format</tt>:: The current file format instance
|
24
|
+
# <tt>options</tt>:: A hash of options that are used by the parser
|
25
|
+
def initialize(format, options = {})
|
26
|
+
@line_definitions = {}
|
27
|
+
@options = options
|
28
|
+
@source_files = options[:source_files]
|
29
|
+
@parsed_requests = 0
|
30
|
+
@requests = []
|
31
|
+
|
32
|
+
self.register_file_format(format)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Reads the input, which can either be a file, sequence of files or STDIN to parse
|
36
|
+
# lines specified in the FileFormat. This lines will be combined into Request instances,
|
37
|
+
# that will be yielded. The actual parsing occurs in the parse_io method.
|
38
|
+
# <tt>options</tt>:: A Hash of options that will be pased to parse_io.
|
39
|
+
def each_request(options = {}, &block) # :yields: request
|
40
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => @source_files)
|
41
|
+
|
42
|
+
@progress_handler.call(:started, @source_files) if @progress_handler
|
43
|
+
RequestLogAnalyzer::Source::CompletedLine.find(:all).each do |request|
|
44
|
+
@parsed_requests += 1
|
45
|
+
yield(request.convert(self.file_format))
|
46
|
+
end
|
47
|
+
|
48
|
+
@progress_handler.call(:finished, @source_files) if @progress_handler
|
49
|
+
end
|
50
|
+
|
51
|
+
# Add a block to this method to install a progress handler while parsing.
|
52
|
+
# <tt>proc</tt>:: The proc that will be called to handle progress update messages
|
53
|
+
def progress=(proc)
|
54
|
+
@progress_handler = proc
|
55
|
+
end
|
56
|
+
|
57
|
+
# Add a block to this method to install a warning handler while parsing,
|
58
|
+
# <tt>proc</tt>:: The proc that will be called to handle parse warning messages
|
59
|
+
def warning=(proc)
|
60
|
+
@warning_handler = proc
|
61
|
+
end
|
62
|
+
|
63
|
+
# This method is called by the parser if it encounteres any parsing problems.
|
64
|
+
# It will call the installed warning handler if any.
|
65
|
+
#
|
66
|
+
# By default, RequestLogAnalyzer::Controller will install a warning handler
|
67
|
+
# that will pass the warnings to each aggregator so they can do something useful
|
68
|
+
# with it.
|
69
|
+
#
|
70
|
+
# <tt>type</tt>:: The warning type (a Symbol)
|
71
|
+
# <tt>message</tt>:: A message explaining the warning
|
72
|
+
def warn(type, message)
|
73
|
+
@warning_handler.call(type, message, @current_io.lineno) if @warning_handler
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -48,7 +48,7 @@ module RequestLogAnalyzer::Tracker
|
|
48
48
|
category = options[:category].respond_to?(:call) ? options[:category].call(request) : request[options[:category]]
|
49
49
|
duration = options[:duration].respond_to?(:call) ? options[:duration].call(request) : request[options[:duration]]
|
50
50
|
|
51
|
-
if
|
51
|
+
if duration.kind_of?(Float) && category.kind_of?(String)
|
52
52
|
@categories[category] ||= {:hits => 0, :cumulative => 0.0, :min => duration, :max => duration }
|
53
53
|
@categories[category][:hits] += 1
|
54
54
|
@categories[category][:cumulative] += duration
|
@@ -72,9 +72,8 @@ module RequestLogAnalyzer::Tracker
|
|
72
72
|
output.table({}, {:align => :right}, {:type => :ratio, :width => :rest, :treshold => 0.15}) do |rows|
|
73
73
|
@request_time_graph.each_with_index do |requests, index|
|
74
74
|
ratio = requests.to_f / total_requests.to_f
|
75
|
-
requests_per_day = requests / days
|
76
|
-
|
77
|
-
rows << ["#{index.to_s.rjust(3)}:00", "#{requests_per_day} hits", ratio]
|
75
|
+
requests_per_day = (requests / days).ceil
|
76
|
+
rows << ["#{index.to_s.rjust(3)}:00", "%d hits" % requests_per_day, ratio]
|
78
77
|
end
|
79
78
|
end
|
80
79
|
end
|
@@ -79,7 +79,7 @@ describe RequestLogAnalyzer::Aggregator::Database, "record insertion" do
|
|
79
79
|
@completed_request = testing_format.request( {:line_type => :first, :request_no => 564},
|
80
80
|
{:line_type => :test, :test_capture => "awesome"},
|
81
81
|
{:line_type => :test, :test_capture => "indeed"},
|
82
|
-
{:line_type => :eval, :evaluated =>
|
82
|
+
{:line_type => :eval, :evaluated => { :greating => 'howdy'}, :greating => 'howdy' },
|
83
83
|
{:line_type => :last, :request_no => 564})
|
84
84
|
end
|
85
85
|
|
@@ -55,7 +55,7 @@ describe RequestLogAnalyzer::LineDefinition, :converting do
|
|
55
55
|
|
56
56
|
it "should merge a hash capture into the line hash" do
|
57
57
|
hash = @file_format.line_definitions[:eval].convert_captured_values(["{ 'greating' => 'hello', 'what' => 'world'}"], @request)
|
58
|
-
hash[:evaluated].should ==
|
58
|
+
hash[:evaluated].should == { :greating => "hello", :what => "world"}
|
59
59
|
hash[:greating].should == 'hello'
|
60
60
|
hash[:what].should == 'world'
|
61
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: request-log-analyzer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5.1
|
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: 2009-02-
|
13
|
+
date: 2009-02-10 00:00:00 +01:00
|
14
14
|
default_executable: request-log-analyzer
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/request_log_analyzer/request.rb
|
63
63
|
- lib/request_log_analyzer/source
|
64
64
|
- lib/request_log_analyzer/source.rb
|
65
|
+
- lib/request_log_analyzer/source/database.rb
|
65
66
|
- lib/request_log_analyzer/source/log_parser.rb
|
66
67
|
- lib/request_log_analyzer/tracker
|
67
68
|
- lib/request_log_analyzer/tracker.rb
|