Class: RequestLogAnalyzer::FileFormat::Oink::Request

Inherits:
Rails::Request show all
Defined in:
lib/request_log_analyzer/file_format/oink.rb

Instance Attribute Summary

Attributes inherited from Request

#attributes, #file_format, #lines

Instance Method Summary collapse

Methods inherited from Rails::Request

#convert_sql, #convert_timestamp

Methods inherited from Request

#<<, #add_line_hash, #add_parsed_line, #completed?, create, #empty?, #every, #first, #first_lineno, #has_line_type?, #initialize, #last_lineno, #timestamp

Methods included from Request::Converters

#convert_decimal, #convert_duration, #convert_epoch, #convert_eval, #convert_float, #convert_int, #convert_integer, #convert_nillable_string, #convert_path, #convert_string, #convert_sym, #convert_symbol, #convert_timestamp, #convert_traffic, #convert_value, #sanitize_parameters

Constructor Details

This class inherits a constructor from RequestLogAnalyzer::Request

Instance Method Details

#convert_pipe_separated_counts(value, _capture_definition) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/request_log_analyzer/file_format/oink.rb', line 84

def convert_pipe_separated_counts(value, _capture_definition)
  count_strings = value.split(' | ')
  count_arrays = count_strings.map do |count_string|
    if count_string =~ /^(\w+): (\d+)/
      [Regexp.last_match[1], Regexp.last_match[2].to_i]
    end
  end

  Hash[count_arrays]
end

#pid_memoryObject

Accessor for memory information associated with the specified request PID. If no memory exists for this request’s :pid, the memory tracking is initialized.



54
55
56
# File 'lib/request_log_analyzer/file_format/oink.rb', line 54

def pid_memory
  file_format.pids[self[:pid]] ||= { last_memory_reading: -1, current_memory_reading: -1 }
end

#update_pidsObject

Calculates :memory_diff for each request based on the last completed request that was not a failure.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/request_log_analyzer/file_format/oink.rb', line 59

def update_pids
  # memory isn't recorded with exceptions. need to set #last_memory_reading+ to -1 as
  # the memory used could have changed. for the next request the memory change will not be recorded.
  #
  # NOTE - the failure regex was not matching with a Rails Development log file.
  if has_line_type?(:failure) && processing = has_line_type?(:processing)
    pid_memory[:last_memory_reading] = -1
  elsif mem_line = has_line_type?(:memory_usage)
    memory_reading = mem_line[:memory]
    pid_memory[:current_memory_reading] = memory_reading
    # calcuate the change in memory
    unless pid_memory[:current_memory_reading] == -1 || pid_memory[:last_memory_reading] == -1
      # logged as kB, need to convert to bytes for the :traffic Tracker
      memory_diff = (pid_memory[:current_memory_reading] - pid_memory[:last_memory_reading]) * 1024
      if memory_diff > 0
        attributes[:memory_diff] = memory_diff
      end # if memory_diff > 0
    end # unless

    pid_memory[:last_memory_reading] = pid_memory[:current_memory_reading]
    pid_memory[:current_memory_reading] = -1
  end # if mem_line
  true
end

#validateObject

Overrides the #validate method to handle PID updating.



47
48
49
50
# File 'lib/request_log_analyzer/file_format/oink.rb', line 47

def validate
  update_pids
  super
end