Class: AbCrunch::AbResult

Inherits:
Object
  • Object
show all
Defined in:
lib/abcrunch/ab_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_ab_output, ab_options) ⇒ AbResult

Returns a new instance of AbResult.



5
6
7
8
# File 'lib/abcrunch/ab_result.rb', line 5

def initialize(raw_ab_output, ab_options)
  @raw = raw_ab_output
  @ab_options = ab_options
end

Instance Attribute Details

#ab_optionsObject

Returns the value of attribute ab_options.



3
4
5
# File 'lib/abcrunch/ab_result.rb', line 3

def ab_options
  @ab_options
end

#rawObject

Returns the value of attribute raw.



3
4
5
# File 'lib/abcrunch/ab_result.rb', line 3

def raw
  @raw
end

Instance Method Details

#avg_response_timeObject



14
15
16
# File 'lib/abcrunch/ab_result.rb', line 14

def avg_response_time
  raw.match(/Time per request:\s*([\d\.]+)\s\[ms\]\s\(mean\)/)[1].to_f
end

#commandObject



10
11
12
# File 'lib/abcrunch/ab_result.rb', line 10

def command
  AbCrunch::AbRunner.ab_command(@ab_options)
end

#failed_requestsObject



22
23
24
# File 'lib/abcrunch/ab_result.rb', line 22

def failed_requests
  raw.match(/Failed requests:\s*([\d\.]+)/)[1].to_i
end

#logObject



26
27
28
29
30
31
# File 'lib/abcrunch/ab_result.rb', line 26

def log
  AbCrunch::Logger.log :ab_result, "#{command}"
  AbCrunch::Logger.log :ab_result, "Average Response Time: #{avg_response_time}"
  AbCrunch::Logger.log :ab_result, "Queries per Second: #{queries_per_second}"
  AbCrunch::Logger.log :ab_result, "Failed requests: #{failed_requests}"
end

#queries_per_secondObject



18
19
20
# File 'lib/abcrunch/ab_result.rb', line 18

def queries_per_second
  raw.match(/Requests per second:\s*([\d\.]+)\s\[#\/sec\]\s\(mean\)/)[1].to_f
end