request-log-analyzer 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/bin/request-log-analyzer +9 -5
  2. data/lib/request_log_analyzer.rb +1 -1
  3. data/lib/request_log_analyzer/aggregator/echo.rb +2 -1
  4. data/lib/request_log_analyzer/aggregator/summarizer.rb +5 -37
  5. data/lib/request_log_analyzer/controller.rb +4 -3
  6. data/lib/request_log_analyzer/file_format.rb +68 -1
  7. data/lib/request_log_analyzer/file_format/amazon_s3.rb +3 -1
  8. data/lib/request_log_analyzer/file_format/apache.rb +7 -2
  9. data/lib/request_log_analyzer/file_format/merb.rb +3 -1
  10. data/lib/request_log_analyzer/file_format/mysql.rb +10 -5
  11. data/lib/request_log_analyzer/file_format/rack.rb +1 -3
  12. data/lib/request_log_analyzer/file_format/rails.rb +5 -5
  13. data/lib/request_log_analyzer/output.rb +4 -0
  14. data/lib/request_log_analyzer/output/fancy_html.rb +31 -0
  15. data/lib/request_log_analyzer/tracker.rb +0 -105
  16. data/lib/request_log_analyzer/tracker/duration.rb +3 -62
  17. data/lib/request_log_analyzer/tracker/frequency.rb +18 -5
  18. data/lib/request_log_analyzer/tracker/numeric_value.rb +223 -0
  19. data/lib/request_log_analyzer/tracker/traffic.rb +6 -72
  20. data/request-log-analyzer.gemspec +4 -4
  21. data/spec/lib/mocks.rb +1 -0
  22. data/spec/unit/file_format/common_regular_expressions_spec.rb +53 -0
  23. data/spec/unit/file_format/mysql_format_spec.rb +1 -2
  24. data/spec/unit/file_format/rails_format_spec.rb +9 -4
  25. data/spec/unit/tracker/duration_tracker_spec.rb +2 -83
  26. data/spec/unit/tracker/{count_tracker_spec.rb → numeric_value_tracker_spec.rb} +50 -7
  27. data/spec/unit/tracker/tracker_api_spec.rb +3 -2
  28. data/spec/unit/tracker/traffic_tracker_spec.rb +0 -79
  29. metadata +8 -5
  30. data/lib/request_log_analyzer/tracker/count.rb +0 -93
@@ -1,93 +0,0 @@
1
- module RequestLogAnalyzer::Tracker
2
-
3
- # Get highest count of a specific attribute
4
- class Count < Base
5
-
6
- include RequestLogAnalyzer::Tracker::StatisticsTracking
7
-
8
- attr_reader :categories
9
-
10
- def prepare
11
- raise "No categorizer set up for category tracker #{self.inspect}" unless options[:category]
12
- raise "No field to count has been set up #{self.inspect}" unless options[:field]
13
-
14
- @categorizer = create_lambda(options[:category])
15
- @counter = create_lambda(options[:field])
16
- @categories = {}
17
- end
18
-
19
- # Get the duration information fron the request and store it in the different categories.
20
- # <tt>request</tt> The request.
21
- def update(request)
22
- category = @categorizer.call(request)
23
- count = @counter.call(request)
24
- update_statistics(category, count) if count.kind_of?(Numeric) && !category.nil?
25
- end
26
-
27
- def report(output)
28
- sortings = output.options[:sort] || [:sum, :mean]
29
-
30
- sortings.each do |report|
31
- case report
32
- when :mean
33
- report_table(output, :mean, :title => "#{title} - sorted by mean")
34
- when :stddev
35
- report_table(output, :stddev, :title => "#{title} - sorted by standard deviation")
36
- when :sum
37
- report_table(output, :sum, :title => "#{title} - sorted by sum")
38
- when :hits
39
- report_table(output, :hits, :title => "#{title} - sorted by hits")
40
- else
41
- raise "Unknown duration report specified: #{report}!"
42
- end
43
- end
44
- end
45
-
46
- # Block function to build a result table using a provided sorting function.
47
- # <tt>output</tt> The output object.
48
- # <tt>amount</tt> The number of rows in the report table (default 10).
49
- # === Options
50
- # * </tt>:title</tt> The title of the table
51
- # * </tt>:sort</tt> The key to sort on (:hits, :cumulative, :average, :min or :max)
52
- def report_table(output, sort, options = {}, &block)
53
- output.puts
54
-
55
- top_categories = output.slice_results(sorted_by(sort))
56
- output.with_style(:top_line => true) do
57
- output.table(*statistics_header(:title => options[:title],:highlight => sort)) do |rows|
58
- top_categories.each { |(cat, info)| rows.push(statistics_row(cat)) }
59
- end
60
- end
61
- output.puts
62
- end
63
-
64
- # Format an int to a nice string with decimal seperation.
65
- # Also see http://en.wikipedia.org/wiki/Terabyte
66
- # <tt>count</tt> the value to reduce
67
- def display_value(count)
68
- return "- " if count.nil?
69
- return "0 " if count.zero?
70
-
71
- case Math.log10(count).floor
72
- when 1...4 then '%d ' % count
73
- when 4...7 then '%dk' % (count / 1000)
74
- when 7...10 then '%dM' % (count / 1000_000)
75
- when 10...13 then '%dG' % (count / 1000_000_000)
76
- when 13...16 then '%dT' % (count / 1000_000_000_000)
77
- else '%dP' % (count / 1000_000_000_000_000)
78
- end
79
-
80
- end
81
-
82
- # Returns the title of this tracker for reports
83
- def title
84
- options[:title] || 'Total'
85
- end
86
-
87
- # Returns all the categories and the tracked duration as a hash than can be exported to YAML
88
- def to_yaml_object
89
- return nil if @categories.empty?
90
- @categories
91
- end
92
- end
93
- end