Module: Net::Fping

Defined in:
lib/net/fping.rb

Class Method Summary collapse

Class Method Details

.alive(hosts = []) ⇒ Object



7
8
9
10
# File 'lib/net/fping.rb', line 7

def alive(hosts=[])
  return [] if hosts.empty?
  %x[fping -a #{hosts.join(" ")} 2>/dev/null].split("\n");
end

.alive_in_range(from, to) ⇒ Object



21
22
23
# File 'lib/net/fping.rb', line 21

def alive_in_range(from, to)
  %x[fping -ag #{from} #{to} 2>/dev/null].split("\n")
end

.alive_in_subnet(subnet) ⇒ Object



17
18
19
# File 'lib/net/fping.rb', line 17

def alive_in_subnet(subnet)
  %x[fping -ag #{subnet} 2>/dev/null].split("\n")
end

.dead(hosts = []) ⇒ Object



12
13
14
15
# File 'lib/net/fping.rb', line 12

def dead(hosts=[])
  return [] if hosts.empty?
  %x[fping -u #{hosts.join(" ")} 2>/dev/null].split("\n")
end

.latency(host, bytes, count, interval) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/net/fping.rb', line 33

def latency(host, bytes, count, interval)
  cmd = "fping -b #{bytes} -c #{count} -q -p #{interval} #{host}"
  Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
    # output is written to stderr for some reason
    ltc = stderr.read.gsub(/[%, ]/, "/")
    ltc = ltc.split(/.*loss\/=\/[0-9]+\/[0-9]+\/([0-9]+)\/\/\/min\/avg\/max\/=\/([0-9.]+)\/([0-9.]+)\/([0-9.]+)/)[-5..4]
	  return ltc
  end
end

.latency_simple(host) ⇒ Object

Added defs for latency based metrics



26
27
28
29
30
31
# File 'lib/net/fping.rb', line 26

def latency_simple(host)
  bytes = 68
  count = 6
  interval = 1000
  %x[fping -b #{bytes} -c #{count} -q -p #{interval} #{host}]
end