class RequestLogAnalyzer::FileFormat::Rails

Default FileFormat class for Rails logs.

Instances will be created dynamically based on the lines you want it to parse. You can specify what lines should be included in the parser by providing a list to the create method as first argument.

Constants

LINE_COLLECTIONS

Definitions of common combinations of lines that can be parsed

LINE_DEFINITIONS

A hash of definitions for all common lines in Rails logs.

RAILS_21_COMPLETED

Rails < 2.1 completed line example Completed in 0.21665 (4 reqs/sec) | Rendering: 0.00926 (4%) | DB: 0.00000 (0%) | 200 OK [demo.nu/employees]

RAILS_22_COMPLETED

Rails > 2.1 completed line example Completed in 614ms (View: 120, DB: 31) | 200 OK [floorplanner.local/demo]

REQUEST_CATEGORIZER

Simple function to categorize Rails requests using controller/actions/format and method.

Public Class Methods

create(lines = 'production') click to toggle source

Creates a Rails FileFormat instance.

The lines that will be parsed can be defined by the argument to this function, which should be an array of line names, or a list of line names as comma separated string. The resulting report depends on the lines that will be parsed. You can also provide s string that describes a common set of lines, like “production”, “development” or “production”.

   # File lib/request_log_analyzer/file_format/rails.rb
17 def self.create(lines = 'production')
18   definitions_hash = line_definer.line_definitions.clone
19 
20   lines = lines.to_s.split(',') if lines.is_a?(String)
21   lines = [lines.to_s]          if lines.is_a?(Symbol)
22 
23   lines.each do |line|
24     line = line.to_sym
25     if LINE_COLLECTIONS.key?(line)
26       LINE_COLLECTIONS[line].each { |l| definitions_hash[l] ||= LINE_DEFINITIONS[l] }
27     elsif LINE_DEFINITIONS.key?(line)
28       definitions_hash[line] ||= LINE_DEFINITIONS[line]
29     else
30       fail "Unrecognized Rails log line name: #{line.inspect}!"
31     end
32   end
33 
34   new(definitions_hash, report_trackers(definitions_hash))
35 end
report_trackers(lines) click to toggle source

Creates trackers based on the specified line definitions.

The more lines that will be parsed, the more information will appear in the report.

   # File lib/request_log_analyzer/file_format/rails.rb
40 def self.report_trackers(lines)
41   analyze = RequestLogAnalyzer::Aggregator::Summarizer::Definer.new
42 
43   analyze.timespan
44   analyze.hourly_spread
45 
46   analyze.frequency category: REQUEST_CATEGORIZER, title: 'Most requested'
47   analyze.frequency :method, title: 'HTTP methods'
48   analyze.frequency :status, title: 'HTTP statuses returned'
49 
50   if lines.key?(:cache_hit)
51     analyze.frequency(category: lambda { |request| request =~ :cache_hit ? 'Cache hit' : 'No hit' },
52                       title: 'Rails action cache hits')
53   end
54 
55   analyze.duration :duration, category: REQUEST_CATEGORIZER, title: 'Request duration',    line_type: :completed
56   analyze.duration :view,     category: REQUEST_CATEGORIZER, title: 'View rendering time', line_type: :completed
57   analyze.duration :db,       category: REQUEST_CATEGORIZER, title: 'Database time',       line_type: :completed
58 
59   analyze.frequency category: REQUEST_CATEGORIZER, title: 'Process blockers (> 1 sec duration)',
60     if: lambda { |request| request[:duration] && request[:duration] > 1.0 }
61 
62   if lines.key?(:failure)
63     analyze.frequency :error, title: 'Failed requests', line_type: :failure
64   end
65 
66   if lines.key?(:rendered)
67     analyze.duration :render_duration, category: :render_file, multiple: true, title: 'Partial rendering duration'
68   end
69 
70   if lines.key?(:query_executed)
71     analyze.duration :query_duration, category: :query_sql, multiple: true, title: 'Query duration'
72   end
73 
74   analyze.trackers + report_definer.trackers
75 end