Class: RequestLogAnalyzer::Tracker::Duration

Inherits:
NumericValue show all
Defined in:
lib/request_log_analyzer/tracker/duration.rb

Overview

Analyze the duration of a specific attribute

Options

  • :category Proc that handles request categorization for given fileformat (REQUEST_CATEGORIZER)

  • :duration The field containing the duration in the request hash.

  • :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 Handle request if this proc is false for the handled request.

The items in the update request hash are set during the creation of the Duration tracker.

Example output:

Request duration - top 20 by cumulative time   |    Hits |      Sum. |      Avg.
---------------------------------------------------------------------------------
EmployeeController#show.html [GET]             |    4742 |  4922.56s |     1.04s
EmployeeController#update.html [POST]          |    4647 |  2731.23s |     0.59s
EmployeeController#index.html [GET]            |    5802 |  1477.32s |     0.25s
.............

Instance Attribute Summary

Attributes inherited from NumericValue

#categories

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from NumericValue

#bucket_average_value, #bucket_index, #bucket_interval, #bucket_lower_bound, #bucket_upper_bound, #bucket_value, #bucketize, #hits, #hits_overall, #max, #mean, #mean_overall, #median, #min, #percentile, #percentile_index, #percentile_indices, #percentile_interval, #report, #report_table, #sorted_by, #statistics_header, #statistics_row, #stddev, #sum, #sum_overall, #to_yaml_object, #update, #update_statistics, #variance

Methods inherited from Base

#create_lambda, #finalize, #initialize, #report, #setup_should_update_checks!, #should_update?, #to_yaml_object, #update

Constructor Details

This class inherits a constructor from RequestLogAnalyzer::Tracker::Base

Instance Method Details

#display_value(time) ⇒ Object

Display a duration



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

def display_value(time)
  case time
  when nil       then '-'
  when 0...1     then '%0ims' % (time * 1000)
  when 1...60    then '%0.02fs' % time
  when 60...3600 then '%dm%02ds' % [time / 60, (time % 60).round]
  else                '%dh%02dm%02ds' % [time / 3600, (time % 3600) / 60, (time % 60).round]
  end
end

#prepareObject

Check if duration and catagory option have been received,



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/request_log_analyzer/tracker/duration.rb', line 23

def prepare
  options[:value] = options[:duration] if options[:duration]
  super

  @number_of_buckets = options[:number_of_buckets] || 1000
  @min_bucket_value  = options[:min_bucket_value] ? options[:min_bucket_value].to_f : 0.0001
  @max_bucket_value  = options[:max_bucket_value] ? options[:max_bucket_value].to_f : 1000

  # precalculate the bucket size
  @bucket_size = (Math.log(@max_bucket_value) - Math.log(@min_bucket_value)) / @number_of_buckets.to_f
end

#titleObject

Returns the title of this tracker for reports



47
48
49
# File 'lib/request_log_analyzer/tracker/duration.rb', line 47

def title
  options[:title]  || 'Request duration'
end