request-log-analyzer 1.9.10 → 1.11.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 (53) hide show
  1. data/.gitignore +4 -1
  2. data/.infinity_test +8 -0
  3. data/Gemfile +2 -0
  4. data/bin/request-log-analyzer +0 -1
  5. data/lib/request_log_analyzer/aggregator/database_inserter.rb +2 -1
  6. data/lib/request_log_analyzer/aggregator.rb +5 -5
  7. data/lib/request_log_analyzer/controller.rb +0 -3
  8. data/lib/request_log_analyzer/database.rb +6 -7
  9. data/lib/request_log_analyzer/file_format/apache.rb +19 -28
  10. data/lib/request_log_analyzer/file_format/delayed_job2.rb +2 -2
  11. data/lib/request_log_analyzer/file_format/delayed_job21.rb +2 -2
  12. data/lib/request_log_analyzer/file_format/haproxy.rb +232 -0
  13. data/lib/request_log_analyzer/file_format/mysql.rb +5 -5
  14. data/lib/request_log_analyzer/file_format/rails3.rb +9 -2
  15. data/lib/request_log_analyzer/file_format/w3c.rb +56 -0
  16. data/lib/request_log_analyzer/file_format.rb +46 -15
  17. data/lib/request_log_analyzer/filter.rb +4 -5
  18. data/lib/request_log_analyzer/line_definition.rb +6 -4
  19. data/lib/request_log_analyzer/output.rb +3 -5
  20. data/lib/request_log_analyzer/request.rb +7 -0
  21. data/lib/request_log_analyzer/source/log_parser.rb +56 -4
  22. data/lib/request_log_analyzer/source.rb +3 -4
  23. data/lib/request_log_analyzer/tracker.rb +8 -8
  24. data/lib/request_log_analyzer.rb +15 -29
  25. data/request-log-analyzer.gemspec +4 -4
  26. data/spec/fixtures/mysql_slow_query.log +0 -1
  27. data/spec/integration/command_line_usage_spec.rb +0 -5
  28. data/spec/lib/helpers.rb +2 -2
  29. data/spec/lib/matchers.rb +38 -7
  30. data/spec/lib/mocks.rb +1 -5
  31. data/spec/spec_helper.rb +3 -2
  32. data/spec/unit/database/base_class_spec.rb +1 -0
  33. data/spec/unit/file_format/amazon_s3_format_spec.rb +58 -55
  34. data/spec/unit/file_format/apache_format_spec.rb +90 -161
  35. data/spec/unit/file_format/common_regular_expressions_spec.rb +51 -26
  36. data/spec/unit/file_format/delayed_job21_format_spec.rb +22 -31
  37. data/spec/unit/file_format/delayed_job2_format_spec.rb +27 -32
  38. data/spec/unit/file_format/delayed_job_format_spec.rb +44 -63
  39. data/spec/unit/file_format/haproxy_format_spec.rb +82 -0
  40. data/spec/unit/file_format/line_definition_spec.rb +26 -33
  41. data/spec/unit/file_format/merb_format_spec.rb +22 -37
  42. data/spec/unit/file_format/mysql_format_spec.rb +80 -123
  43. data/spec/unit/file_format/oink_format_spec.rb +29 -61
  44. data/spec/unit/file_format/postgresql_format_spec.rb +10 -21
  45. data/spec/unit/file_format/rack_format_spec.rb +49 -44
  46. data/spec/unit/file_format/rails3_format_spec.rb +46 -38
  47. data/spec/unit/file_format/rails_format_spec.rb +52 -68
  48. data/spec/unit/file_format/w3c_format_spec.rb +47 -0
  49. data/spec/unit/source/log_parser_spec.rb +1 -1
  50. metadata +12 -7
  51. data/lib/mixins/gets_memory_protection.rb +0 -80
  52. data/lib/request_log_analyzer/output/fancy_html.rb +0 -44
  53. data/lib/request_log_analyzer/source/database_loader.rb +0 -87
@@ -1,44 +0,0 @@
1
- begin
2
- require 'rubygems'
3
- require 'gchart'
4
- rescue LoadError
5
- $stderr.puts "The FancyHTML output format requires the googlechart gem:"
6
- $stderr.puts " (sudo) gem install googlecharts"
7
- end
8
-
9
- module RequestLogAnalyzer::Output
10
-
11
- class FancyHTML < HTML
12
-
13
- def report_tracker(tracker)
14
- case tracker
15
- when RequestLogAnalyzer::Tracker::HourlySpread then report_hourly_spread(tracker)
16
- else tracker.report(self)
17
- end
18
- end
19
-
20
- def report_hourly_spread(tracker)
21
- title tracker.title
22
- puts tag(:img, nil, :width => '700', :height => '120', :src =>
23
- Gchart.sparkline(:data => tracker.hour_frequencies, :size => '700x120', :line_colors => '0077CC',
24
- :axis_with_labels => 'x,y', :axis_labels => [x_axis_labels(tracker),y_axis_labels(tracker)]))
25
- end
26
-
27
- def x_axis_labels(tracker)
28
- frmt = '%H:%M'
29
- x_axis_labels = []
30
- num_labels = 5
31
- start = tracker.first_timestamp
32
- step = tracker.timespan / (num_labels - 1)
33
- for i in 0...num_labels do
34
- x_axis_labels << (start + step * i).strftime(frmt)
35
- end
36
- x_axis_labels
37
- end
38
-
39
- def y_axis_labels(tracker)
40
- sorted_frequencies = tracker.hour_frequencies.sort
41
- [sorted_frequencies.first, sorted_frequencies.last]
42
- end
43
- end
44
- end
@@ -1,87 +0,0 @@
1
- require 'rubygems'
2
- require 'activerecord'
3
-
4
- module RequestLogAnalyzer::Source
5
-
6
- # Active Resource hook
7
- class Request < ActiveRecord::Base
8
- has_many :completed_lines
9
- has_many :processing_lines
10
- def convert(file_format)
11
- send_attributes = self.attributes
12
- send_attributes.merge!(self.completed_lines.first.attributes) if self.completed_lines.first
13
- send_attributes.merge!(self.processing_lines.first.attributes) if self.processing_lines.first
14
- return RequestLogAnalyzer::Request.new(file_format, send_attributes)
15
- end
16
- end
17
-
18
- class CompletedLine < ActiveRecord::Base
19
- belongs_to :request
20
- end
21
-
22
- class ProcessingLine < ActiveRecord::Base
23
- belongs_to :request
24
- end
25
-
26
- # The Database class gets log data from the database.
27
- class DatabaseLoader < Base
28
-
29
- attr_reader :source_files, :file_format, :requests
30
-
31
- # Initializes the log file parser instance.
32
- # It will apply the language specific FileFormat module to this instance. It will use the line
33
- # definitions in this module to parse any input that it is given (see parse_io).
34
- #
35
- # <tt>format</tt>:: The current file format instance
36
- # <tt>options</tt>:: A hash of options that are used by the parser
37
- def initialize(format, options = {})
38
- super(format, options)
39
- @source_files = options[:source_files]
40
- @parsed_requests = 0
41
- @requests = []
42
- end
43
-
44
- # Reads the input, which can either be a file, sequence of files or STDIN to parse
45
- # lines specified in the FileFormat. This lines will be combined into Request instances,
46
- # that will be yielded. The actual parsing occurs in the parse_io method.
47
- # <tt>options</tt>:: A Hash of options that will be pased to parse_io.
48
- def each_request(options = {}, &block) # :yields: request
49
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => @source_files)
50
-
51
- @progress_handler.call(:started, @source_files) if @progress_handler
52
- RequestLogAnalyzer::Source::Request.find(:all).each do |request|
53
- @parsed_requests += 1
54
- @progress_handler.call(:progress, @parsed_requests) if @progress_handler
55
-
56
- yield request.convert(self.file_format)
57
- end
58
-
59
- @progress_handler.call(:finished, @source_files) if @progress_handler
60
- end
61
-
62
- # Add a block to this method to install a progress handler while parsing.
63
- # <tt>proc</tt>:: The proc that will be called to handle progress update messages
64
- def progress=(proc)
65
- @progress_handler = proc
66
- end
67
-
68
- # Add a block to this method to install a warning handler while parsing,
69
- # <tt>proc</tt>:: The proc that will be called to handle parse warning messages
70
- def warning=(proc)
71
- @warning_handler = proc
72
- end
73
-
74
- # This method is called by the parser if it encounteres any parsing problems.
75
- # It will call the installed warning handler if any.
76
- #
77
- # By default, RequestLogAnalyzer::Controller will install a warning handler
78
- # that will pass the warnings to each aggregator so they can do something useful
79
- # with it.
80
- #
81
- # <tt>type</tt>:: The warning type (a Symbol)
82
- # <tt>message</tt>:: A message explaining the warning
83
- def warn(type, message)
84
- @warning_handler.call(type, message, @current_io.lineno) if @warning_handler
85
- end
86
- end
87
- end