Class: NetworkMonitor

Inherits:
TimingTest show all
Defined in:
lib/load/monitors/network_monitor.rb

Instance Attribute Summary collapse

Attributes inherited from TimingTest

#index, #logger, #owner, #params, #target_code

Instance Method Summary collapse

Methods inherited from TimingTest

#assert, #ellaped_millis, #log, #server_url, #set_up, #tear_down, #time_block

Constructor Details

#initialize(address) ⇒ NetworkMonitor

Returns a new instance of NetworkMonitor.



8
9
10
11
# File 'lib/load/monitors/network_monitor.rb', line 8

def initialize(address)
  @sleep_seconds = 4
  @address = address
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



6
7
8
# File 'lib/load/monitors/network_monitor.rb', line 6

def address
  @address
end

Instance Method Details

#pause_after_runObject

64 bytes from localhost (127.0.0.1): icmp_req=4 ttl=64 time=0.015 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.018 ms



38
39
40
# File 'lib/load/monitors/network_monitor.rb', line 38

def pause_after_run
  sleep @sleep_seconds
end

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/load/monitors/network_monitor.rb', line 17

def run
  output = ""
  begin
    timing = 0
    pinger = Net::Ping::External.new
    (1..10).each do
      pinger.ping(@address)
      timing += (pinger.duration * 1000.0)
    end
    puts "Ping timing for 10 pings: #{timing}"
    @timing = timing
  rescue Exception
    @timing = nil
    puts "Error pinging address: #{@address}    =>   #{output}"
    raise "Error pinging address: #{@address}    =>   #{output}"
  end
end

#test_codeObject



42
43
44
# File 'lib/load/monitors/network_monitor.rb', line 42

def test_code
  return ("monitor.network")
end

#timingObject



13
14
15
# File 'lib/load/monitors/network_monitor.rb', line 13

def timing
  return @timing
end