Class: LogParser::LogEntry
- Inherits:
-
Object
- Object
- LogParser::LogEntry
- Defined in:
- lib/production_log/parser.rb
Overview
LogEntry contains a summary of log data for a single request.
Instance Attribute Summary collapse
-
#db_time ⇒ Object
readonly
Total database time.
-
#ip ⇒ Object
readonly
Requesting IP.
-
#page ⇒ Object
readonly
Controller and action for this request.
-
#queries ⇒ Object
readonly
Array of SQL queries containing query type and time taken.
-
#query_count ⇒ Object
readonly
Creates a new LogEntry from the log data in
entry
. -
#render_time ⇒ Object
readonly
Total render time.
-
#request_size ⇒ Object
readonly
Creates a new LogEntry from the log data in
entry
. -
#request_time ⇒ Object
readonly
Total request time, including database, render and other.
-
#response_size ⇒ Object
readonly
Creates a new LogEntry from the log data in
entry
. -
#row_count ⇒ Object
readonly
Creates a new LogEntry from the log data in
entry
. -
#time ⇒ Object
readonly
Time the request was made.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
-
#initialize(entry) ⇒ LogEntry
constructor
A new instance of LogEntry.
-
#parse(entry) ⇒ Object
Extracts log data from
entry
, which is an Array of lines from the same request.
Constructor Details
#initialize(entry) ⇒ LogEntry
Returns a new instance of LogEntry.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/production_log/parser.rb', line 69 def initialize(entry) @page = nil @ip = nil @time = nil @queries = [] @request_time = 0 @render_time = 0 @db_time = 0 @in_component = 0 parse entry end |
Instance Attribute Details
#db_time ⇒ Object (readonly)
Total database time
62 63 64 |
# File 'lib/production_log/parser.rb', line 62 def db_time @db_time end |
#ip ⇒ Object (readonly)
Requesting IP
36 37 38 |
# File 'lib/production_log/parser.rb', line 36 def ip @ip end |
#page ⇒ Object (readonly)
Controller and action for this request
31 32 33 |
# File 'lib/production_log/parser.rb', line 31 def page @page end |
#queries ⇒ Object (readonly)
Array of SQL queries containing query type and time taken. The complete text of the SQL query is not saved to reduct memory usage.
47 48 49 |
# File 'lib/production_log/parser.rb', line 47 def queries @queries end |
#query_count ⇒ Object (readonly)
Creates a new LogEntry from the log data in entry
.
67 68 69 |
# File 'lib/production_log/parser.rb', line 67 def query_count @query_count end |
#render_time ⇒ Object (readonly)
Total render time.
57 58 59 |
# File 'lib/production_log/parser.rb', line 57 def render_time @render_time end |
#request_size ⇒ Object (readonly)
Creates a new LogEntry from the log data in entry
.
67 68 69 |
# File 'lib/production_log/parser.rb', line 67 def request_size @request_size end |
#request_time ⇒ Object (readonly)
Total request time, including database, render and other.
52 53 54 |
# File 'lib/production_log/parser.rb', line 52 def request_time @request_time end |
#response_size ⇒ Object (readonly)
Creates a new LogEntry from the log data in entry
.
67 68 69 |
# File 'lib/production_log/parser.rb', line 67 def response_size @response_size end |
#row_count ⇒ Object (readonly)
Creates a new LogEntry from the log data in entry
.
67 68 69 |
# File 'lib/production_log/parser.rb', line 67 def row_count @row_count end |
#time ⇒ Object (readonly)
Time the request was made
41 42 43 |
# File 'lib/production_log/parser.rb', line 41 def time @time end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/production_log/parser.rb', line 150 def ==(other) # :nodoc: other.class == self.class and other.page == self.page and other.ip == self.ip and other.time == self.time and other.queries == self.queries and other.request_time == self.request_time and other.render_time == self.render_time and other.db_time == self.db_time end |
#parse(entry) ⇒ Object
Extracts log data from entry
, which is an Array of lines from the same request.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/production_log/parser.rb', line 86 def parse(entry) entry.each do |line| case line when /^Parameters/, /^Cookie set/, /^Rendering/, /^Redirected/ then # nothing when /^Processing ([\S]+) \(for (.+) at (.*)\)/ then next if @in_component > 0 @page = $1 @ip = $2 @time = $3 when /^Completed in ([\S]+) \(\d* reqs\/sec\) \| (.+)/, /^Completed in ([\S]+) \((.+)\)/ then next if @in_component > 0 # handle millisecond times as well as fractional seconds @times_in_milliseconds = $1[-2..-1] == 'ms' @request_time = @times_in_milliseconds ? ($1.to_i/1000.0) : $1.to_f log_info = $2 log_info = log_info.split(/[,|]/) log_info = log_info.map do |entry| next nil unless entry.index(': ') result = entry.strip.split(': ') if result.size > 2 result = [result[0], result[1..-1].join(':')] end result end.compact.flatten log_info = Hash[*log_info] @row_count = log_info['Rows'].to_i @query_count = log_info['Queries'].to_i @request_size = log_info['Request Size'].to_i @response_size = log_info['Response Size'].to_i @page = log_info['Processed'] if log_info['Processed'] @page += ".#{log_info['Response Format']}" if log_info['Response Format'] if x = (log_info['DB']) x = x.split(' ').first @db_time = @times_in_milliseconds ? (x.to_i/1000.0) : x.to_f end if x = (log_info['Rendering'] || log_info['View']) x = x.split(' ').first @render_time = @times_in_milliseconds ? (x.to_i/1000.0) : x.to_f end when /(.+?) \(([^)]+)\) / then @queries << [$1, $2.to_f] when /^Start rendering component / then @in_component += 1 when /^End of component rendering$/ then @in_component -= 1 when /^Fragment hit: / then else # noop # raise "Can't handle #{line.inspect}" if $TESTING end end end |