Class: RequestLogAnalyzer::Tracker::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/request_log_analyzer/tracker.rb

Overview

Base Tracker class. All other trackers inherit from this class

Accepts the following options:

  • :if Proc that has to return !nil for a request to be passed to the tracker.

  • :line_type The line type that contains the duration field (determined by the category proc).

  • :output Direct output here (defaults to STDOUT)

  • :unless Proc that has to return nil for a request to be passed to the tracker.

For example :if => lambda { |request| request && request > 1.0 }

Direct Known Subclasses

Duration, Frequency, HourlySpread, Timespan, Traffic

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Initialize the class Note that the options are only applicable if should_update? is not overwritten by the inheriting class.

Options

  • :if Handle request if this proc is true for the handled request.

  • :unless Handle request if this proc is false for the handled request.

  • :line_type Line type this tracker will accept.



30
31
32
33
# File 'lib/request_log_analyzer/tracker.rb', line 30

def initialize(options ={})
  @options = options
  setup_should_update_checks!
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



20
21
22
# File 'lib/request_log_analyzer/tracker.rb', line 20

def options
  @options
end

Instance Method Details

#finalizeObject

Hook things that need to be done after running here.



55
56
# File 'lib/request_log_analyzer/tracker.rb', line 55

def finalize
end

#prepareObject

Hook things that need to be done before running here.



46
47
# File 'lib/request_log_analyzer/tracker.rb', line 46

def prepare
end

#report(output) ⇒ Object

Hook report generation here. Defaults to self.inspect output The output object the report will be passed to.



75
76
77
78
# File 'lib/request_log_analyzer/tracker.rb', line 75

def report(output)
  output << self.inspect
  output << "\n"  
end

#setup_should_update_checks!Object

Sets up the tracker’s should_update? checks.



36
37
38
39
40
41
42
43
# File 'lib/request_log_analyzer/tracker.rb', line 36

def setup_should_update_checks!
  @should_update_checks = []
  @should_update_checks.push( lambda { |request| request.has_line_type?(options[:line_type]) } ) if options[:line_type]
  @should_update_checks.push(options[:if]) if options[:if].respond_to?(:call)
  @should_update_checks.push( lambda { |request| request[options[:if]] }) if options[:if].kind_of?(Symbol)
  @should_update_checks.push( lambda { |request| !options[:unless].call(request) }) if options[:unless].respond_to?(:call)
  @should_update_checks.push( lambda { |request| !request[options[:unless]] }) if options[:unless].kind_of?(Symbol)
end

#should_update?(request) ⇒ Boolean

Determine if we should run the update function at all. Usually the update function will be heavy, so a light check is done here determining if we need to call update at all.

Default this checks if defined:

* :line_type is also in the request hash.
* :if is true for this request.
* :unless if false for this request

request The request object.

Returns:

  • (Boolean)


68
69
70
# File 'lib/request_log_analyzer/tracker.rb', line 68

def should_update?(request)
  @should_update_checks.all? { |c| c.call(request) }
end

#titleObject

The title of this tracker. Used for reporting.



81
82
83
# File 'lib/request_log_analyzer/tracker.rb', line 81

def title
  self.class.to_s
end

#to_yaml_objectObject

This method is called by RequestLogAnalyzer::Aggregator:Summarizer to retrieve an object with all the results of this tracker, that can be dumped to YAML format.



87
88
89
# File 'lib/request_log_analyzer/tracker.rb', line 87

def to_yaml_object
  nil
end

#update(request) ⇒ Object

Will be called with each request. request The request to track data in.



51
52
# File 'lib/request_log_analyzer/tracker.rb', line 51

def update(request)
end