Class: RequestLogAnalyzer::Tracker::Timespan
- Defined in:
- lib/request_log_analyzer/tracker/timespan.rb
Overview
Determines the datetime of the first request and the last request Also determines the amount of days inbetween these.
Accepts the following options:
-
:field
The timestamp field that is looked at. Defaults to :timestamp. -
: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). -
:title
Title do be displayed above the report. -
:unless
Proc that has to return nil for a request to be passed to the tracker.
Expects the following items in the update request hash
-
:timestamp
in YYYYMMDDHHMMSS format.
Example output:
First request: 2008-07-13 06:25:06
Last request: 2008-07-20 06:18:06
Total time analyzed: 7 days
Instance Attribute Summary collapse
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#request_time_graph ⇒ Object
readonly
Returns the value of attribute request_time_graph.
Attributes inherited from Base
Instance Method Summary collapse
-
#first_timestamp ⇒ Object
First timestamp encountered.
-
#last_timestamp ⇒ Object
Last timestamp encountered.
-
#prepare ⇒ Object
Check if timestamp field is set in the options.
-
#report(output) ⇒ Object
Generate an hourly spread report to the given output object.
-
#timespan ⇒ Object
Difference between last and first timestamp.
-
#title ⇒ Object
Returns the title of this tracker for reports.
-
#to_yaml_object ⇒ Object
A hash that can be exported to YAML with the first and last timestamp encountered.
-
#update(request) ⇒ Object
Check if the timestamp in the request and store it.
Methods inherited from Base
#finalize, #initialize, #setup_should_update_checks!, #should_update?
Constructor Details
This class inherits a constructor from RequestLogAnalyzer::Tracker::Base
Instance Attribute Details
#first ⇒ Object (readonly)
Returns the value of attribute first.
22 23 24 |
# File 'lib/request_log_analyzer/tracker/timespan.rb', line 22 def first @first end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
22 23 24 |
# File 'lib/request_log_analyzer/tracker/timespan.rb', line 22 def last @last end |
#request_time_graph ⇒ Object (readonly)
Returns the value of attribute request_time_graph.
22 23 24 |
# File 'lib/request_log_analyzer/tracker/timespan.rb', line 22 def request_time_graph @request_time_graph end |
Instance Method Details
#first_timestamp ⇒ Object
First timestamp encountered
39 40 41 |
# File 'lib/request_log_analyzer/tracker/timespan.rb', line 39 def DateTime.parse(@first.to_s, '%Y%m%d%H%M%S') rescue nil end |
#last_timestamp ⇒ Object
Last timestamp encountered
44 45 46 |
# File 'lib/request_log_analyzer/tracker/timespan.rb', line 44 def DateTime.parse(@last.to_s, '%Y%m%d%H%M%S') rescue nil end |
#prepare ⇒ Object
Check if timestamp field is set in the options.
25 26 27 |
# File 'lib/request_log_analyzer/tracker/timespan.rb', line 25 def prepare [:field] ||= :timestamp end |
#report(output) ⇒ Object
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
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/request_log_analyzer/tracker/timespan.rb', line 56 def report(output) output.title([:title]) if [:title] if @last && @first output.with_style(:cell_separator => false) do output.table({:width => 20}, {}) do |rows| rows << ['First request:', .strftime('%Y-%m-%d %H:%M:%I')] rows << ['Last request:', .strftime('%Y-%m-%d %H:%M:%I')] rows << ['Total time analyzed:', "#{timespan.ceil} days"] end end end end |
#timespan ⇒ Object
Difference between last and first timestamp.
49 50 51 |
# File 'lib/request_log_analyzer/tracker/timespan.rb', line 49 def timespan - end |
#title ⇒ Object
Returns the title of this tracker for reports
71 72 73 |
# File 'lib/request_log_analyzer/tracker/timespan.rb', line 71 def title [:title] || 'Request timespan' end |
#to_yaml_object ⇒ Object
A hash that can be exported to YAML with the first and last timestamp encountered.
76 77 78 |
# File 'lib/request_log_analyzer/tracker/timespan.rb', line 76 def to_yaml_object { :first => , :last => } end |
#update(request) ⇒ Object
Check if the timestamp in the request and store it. request
The request.
31 32 33 34 35 36 |
# File 'lib/request_log_analyzer/tracker/timespan.rb', line 31 def update(request) = request[[:field]] @first = if @first.nil? || < @first @last = if @last.nil? || > @last end |