class RequestLogAnalyzer::Tracker::Timespan

Determines the datetime of the first request and the last request Also determines the amount of days inbetween these.

Accepts the following options:

Expects the following items in the update request hash

Example output:

First request:        2008-07-13 06:25:06
Last request:         2008-07-20 06:18:06
Total time analyzed:  7 days

Attributes

first[R]
last[R]

Public Instance Methods

first_timestamp() click to toggle source

First timestamp encountered

   # File lib/request_log_analyzer/tracker/timespan.rb
37 def first_timestamp
38   DateTime.parse(@first.to_s, '%Y%m%d%H%M%S') rescue nil
39 end
last_timestamp() click to toggle source

Last timestamp encountered

   # File lib/request_log_analyzer/tracker/timespan.rb
42 def last_timestamp
43   DateTime.parse(@last.to_s, '%Y%m%d%H%M%S') rescue nil
44 end
prepare() click to toggle source

Check if timestamp field is set in the options.

   # File lib/request_log_analyzer/tracker/timespan.rb
23 def prepare
24   options[:field] ||= :timestamp
25   @first, @last = 99_999_999_999_999, 0
26 end
report(output) click to toggle source

Generate an hourly spread report to the given output object. Any options for the report should have been set during initialize. output The output object

   # File lib/request_log_analyzer/tracker/timespan.rb
54 def report(output)
55   output.title(options[:title]) if options[:title]
56 
57   if @last > 0 && @first < 99_999_999_999_999
58     output.with_style(cell_separator: false) do
59       output.table({ width: 20 }, {}) do |rows|
60         rows << ['First request:', first_timestamp.strftime('%Y-%m-%d %H:%M:%I')]
61         rows << ['Last request:',  last_timestamp.strftime('%Y-%m-%d %H:%M:%I')]
62         rows << ['Total time analyzed:', "#{timespan.ceil} days"]
63       end
64     end
65   end
66 end
timespan() click to toggle source

Difference between last and first timestamp.

   # File lib/request_log_analyzer/tracker/timespan.rb
47 def timespan
48   last_timestamp - first_timestamp
49 end
title() click to toggle source

Returns the title of this tracker for reports

   # File lib/request_log_analyzer/tracker/timespan.rb
69 def title
70   options[:title] || 'Request timespan'
71 end
to_yaml_object() click to toggle source

A hash that can be exported to YAML with the first and last timestamp encountered.

   # File lib/request_log_analyzer/tracker/timespan.rb
74 def to_yaml_object
75   { first: first_timestamp, last: last_timestamp }
76 end
update(request) click to toggle source

Check if the timestamp in the request and store it. request The request.

   # File lib/request_log_analyzer/tracker/timespan.rb
30 def update(request)
31   timestamp = request[options[:field]]
32   @first = timestamp if timestamp < @first
33   @last  = timestamp if timestamp > @last
34 end