Class: ZombieCheck::Ping::CheckerReport

Inherits:
Object
  • Object
show all
Defined in:
lib/zombie_check/ping/checker_report.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.nodesObject

Returns the value of attribute nodes.



8
9
10
# File 'lib/zombie_check/ping/checker_report.rb', line 8

def nodes
  @nodes
end

Class Method Details

.store(ping) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/zombie_check/ping/checker_report.rb', line 10

def store(ping)
  if ping.stored?
    nodes[ping.host].durations += ping.durations
    nodes[ping.host].lost += ping.lost
  else
    nodes[ping.host] = ping
  end
end

Instance Method Details

#<<(ping) ⇒ Object



20
21
22
# File 'lib/zombie_check/ping/checker_report.rb', line 20

def <<(ping)
  store(HostStat.new(ping))
end

#generateObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zombie_check/ping/checker_report.rb', line 24

def generate
  [].tap do |result|
    nodes.each_pair do |host, node|
      total = node.durations.size + node.lost
      percentage = total > 0 ? (node.lost.to_f / total * 100).round(PRECISION) : 0
      result << <<-REPORT

To #{host} total sent #{total} pings, lost #{node.lost} (#{percentage}%). Time(ms):
AVG #{node.durations.mean.round(PRECISION)} MIN #{node.durations.min} \
MAX #{node.durations.max} sigma #{node.durations.sigma.round(PRECISION)} \
median #{node.durations.median.round(PRECISION)}
  REPORT
    end
  end.join "\n"
end