Sha256: 6976fa827ab42507efcee0d9f4ba96dc0a8ffae9907002c85a0f4ef593b3e0e0
Contents?: true
Size: 1.44 KB
Versions: 3
Compression:
Stored size: 1.44 KB
Contents
module RequestLogAnalyzer::Tracker # Analyze the average and total traffic of requests # # === Options # * <tt>:category</tt> Proc that handles request categorization for given fileformat (REQUEST_CATEGORIZER) # * <tt>:traffic</tt> The field containing the duration in the request hash. # * <tt>:if</tt> Proc that has to return !nil for a request to be passed to the tracker. # * <tt>:line_type</tt> The line type that contains the duration field (determined by the category proc). # * <tt>:title</tt> Title do be displayed above the report # * <tt>:unless</tt> Handle request if this proc is false for the handled request. class Traffic < NumericValue # Check if duration and catagory option have been received, def prepare options[:value] = options[:traffic] if options[:traffic] options[:total] = true super end # Formats the traffic number using x B/kB/MB/GB etc notation def display_value(bytes) return "-" if bytes.nil? return "0 B" if bytes.zero? case Math.log10(bytes).floor when 0...4 then '%d B' % bytes when 4...7 then '%d kB' % (bytes / 1000) when 7...10 then '%d MB' % (bytes / 1000_000) when 10...13 then '%d GB' % (bytes / 1000_000_000) else '%d TB' % (bytes / 1000_000_000_000) end end # Returns the title of this tracker for reports def title options[:title] || 'Request traffic' end end end
Version data entries
3 entries across 3 versions & 1 rubygems