Class: Apdex::CalculateFromLog

Inherits:
Object
  • Object
show all
Defined in:
lib/apdex/calculate_from_log.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ CalculateFromLog

Returns a new instance of CalculateFromLog.



6
7
8
# File 'lib/apdex/calculate_from_log.rb', line 6

def initialize(params={})
  @time_column = params[:time_column] || raise(ArgumentError, "You must specify a time_column")
end

Instance Attribute Details

#time_columnObject (readonly)

Returns the value of attribute time_column.



4
5
6
# File 'lib/apdex/calculate_from_log.rb', line 4

def time_column
  @time_column
end

Instance Method Details

#call(threshold, input) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/apdex/calculate_from_log.rb', line 20

def call(threshold, input)
  values = input.map do |line|
    `echo '#{line.strip}' | awk '{print $11}'`.strip.to_f
  end
  output = {}
  output[:satisfied] = output[:tolerating] = output[:frustrated] = 0
  values.each do |value|
    if value <= threshold
      output[:satisfied] += 1
    elsif value <= (threshold * 4)
      output[:tolerating] += 1
    else
      output[:frustrated] += 1
    end
  end
  output[:score] = ("%0.3f" % (1.0 * (output[:satisfied] + output[:tolerating] / 2) / values.size)).to_f
  output
end


10
11
12
13
14
15
16
17
18
# File 'lib/apdex/calculate_from_log.rb', line 10

def print(threshold, input)
  values = call(threshold, input)
  [
    "Score: #{values[:score]}",
    "Satisfied: #{values[:satisfied]}",
    "Tolerating: #{values[:tolerating]}",
    "Frustrated: #{values[:frustrated]}",
  ].join("\n")
end