class RequestLogAnalyzer::Tracker::Traffic
Analyze the average and total traffic of requests
Options¶ ↑
-
:category
Proc that handles request categorization for given fileformat (REQUEST_CATEGORIZER) -
:traffic
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.
Public Instance Methods
display_value(bytes)
click to toggle source
Formats the traffic number using x B/kB/MB/GB etc notation
# File lib/request_log_analyzer/tracker/traffic.rb 27 def display_value(bytes) 28 return '-' if bytes.nil? 29 return '0 B' if bytes.zero? 30 31 case [Math.log10(bytes.abs).floor, 0].max 32 when 0...4 then '%d B' % bytes 33 when 4...7 then '%d kB' % (bytes / 1000) 34 when 7...10 then '%d MB' % (bytes / 1_000_000) 35 when 10...13 then '%d GB' % (bytes / 1_000_000_000) 36 else '%d TB' % (bytes / 1_000_000_000_000) 37 end 38 end
prepare()
click to toggle source
Check if duration and catagory option have been received,
Calls superclass method
RequestLogAnalyzer::Tracker::NumericValue#prepare
# File lib/request_log_analyzer/tracker/traffic.rb 13 def prepare 14 options[:value] = options[:traffic] if options[:traffic] 15 options[:total] = true 16 super 17 18 @number_of_buckets = options[:number_of_buckets] || 1000 19 @min_bucket_value = options[:min_bucket_value] ? options[:min_bucket_value].to_f : 1 20 @max_bucket_value = options[:max_bucket_value] ? options[:max_bucket_value].to_f : 1_000_000_000_000 21 22 # precalculate the bucket size 23 @bucket_size = (Math.log(@max_bucket_value) - Math.log(@min_bucket_value)) / @number_of_buckets.to_f 24 end
title()
click to toggle source
Returns the title of this tracker for reports
# File lib/request_log_analyzer/tracker/traffic.rb 41 def title 42 options[:title] || 'Request traffic' 43 end