zombie_check 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +19 -0
- data/bin/zombie_check +0 -1
- data/lib/zombie_check/ping/checker.rb +10 -8
- data/lib/zombie_check/ping/checker_report.rb +9 -22
- data/lib/zombie_check/ping/host_stat.rb +46 -0
- data/lib/zombie_check/ping.rb +6 -0
- data/lib/zombie_check/version.rb +1 -1
- data/lib/zombie_check.rb +2 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da130e4c71bccc19171d3c39de7aaffa673bb31b
|
4
|
+
data.tar.gz: 2638fd4b6a1327b88db32ad533bf20f54390cac3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fec0d2135d0c1033f7d7c806c0a958004243351ead9935032d2c172e72f6b7b4083d72fb7505449297a214dbeb1ce1c4902526ec9f2e718be4acd09720561564
|
7
|
+
data.tar.gz: 020caad88071704c47982ff2cd5a46fdee7bc774d80840f73748afa7a1fe45e9a906e2c92e1c57d49fdf2f28f86c98cf78ea7333779bf3ef2e81bdb428a880f1
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/bin/zombie_check
CHANGED
@@ -6,23 +6,19 @@ module ZombieCheck
|
|
6
6
|
|
7
7
|
def initialize(options = {})
|
8
8
|
@hosts_file ||= options[:hosts_file] || "hosts.txt"
|
9
|
-
@delay ||= (options[:delay] || 1000).to_i
|
9
|
+
@delay ||= (options[:delay] || 1000).to_i
|
10
10
|
@hosts ||= []
|
11
11
|
@report = CheckerReport.new
|
12
12
|
setup_interruptor
|
13
13
|
end
|
14
14
|
|
15
15
|
def start
|
16
|
-
puts "Using file #{hosts_file}, delay #{delay}, for exit press Ctrl+C"
|
16
|
+
puts "Using file #{hosts_file}, delay #{delay}ms, for exit press Ctrl+C"
|
17
17
|
loop do
|
18
18
|
update_hosts!
|
19
19
|
@hosts.each { |host| Thread.new { ping host } }
|
20
|
-
if interrupted
|
21
|
-
|
22
|
-
puts @report.generate
|
23
|
-
exit 0
|
24
|
-
end
|
25
|
-
sleep @delay
|
20
|
+
interrupted_exit! if interrupted
|
21
|
+
sleep @delay / 1000.0
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
@@ -64,6 +60,12 @@ module ZombieCheck
|
|
64
60
|
def exit_all_threads!
|
65
61
|
Thread.list.reject { |t| t == Thread.current }.each(&:exit)
|
66
62
|
end
|
63
|
+
|
64
|
+
def interrupted_exit!
|
65
|
+
exit_all_threads!
|
66
|
+
puts @report.generate
|
67
|
+
exit 0
|
68
|
+
end
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
@@ -1,37 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'pry'
|
2
3
|
module ZombieCheck
|
3
4
|
module Ping
|
4
5
|
class CheckerReport
|
5
|
-
PRECISION = 3
|
6
|
-
attr_accessor :stat
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@stat ||= {}
|
10
|
-
end
|
11
6
|
|
12
7
|
def <<(ping)
|
13
|
-
|
14
|
-
host[:durations] ||= []
|
15
|
-
host[:lost] ||= 0
|
16
|
-
if (ping_duration = ping.duration)
|
17
|
-
host[:durations] << (ping_duration * 1000).round(PRECISION)
|
18
|
-
else
|
19
|
-
host[:lost] += 1
|
20
|
-
end
|
8
|
+
HostStat.new(ping).store
|
21
9
|
end
|
22
10
|
|
23
11
|
def generate
|
24
12
|
[].tap do |result|
|
25
|
-
|
26
|
-
total =
|
27
|
-
percentage = total > 0 ?
|
28
|
-
|
13
|
+
HostStat.nodes.each_pair do |host, node|
|
14
|
+
total = node.durations.size + node.lost
|
15
|
+
percentage = total > 0 ? node.lost / total : 0
|
29
16
|
result << <<-REPORT
|
30
17
|
|
31
|
-
To #{host} total sent #{total} pings, lost #{
|
32
|
-
AVG #{
|
33
|
-
MAX #{
|
34
|
-
median #{
|
18
|
+
To #{host} total sent #{total} pings, lost #{node.lost} (#{percentage}%). Time(ms):
|
19
|
+
AVG #{node.durations.mean.round(PRECISION)} MIN #{node.durations.min} \
|
20
|
+
MAX #{node.durations.max} sigma #{node.durations.sigma.round(PRECISION)} \
|
21
|
+
median #{node.durations.median.round(PRECISION)}
|
35
22
|
REPORT
|
36
23
|
end
|
37
24
|
end.join "\n"
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ZombieCheck
|
3
|
+
module Ping
|
4
|
+
class HostStat
|
5
|
+
@nodes = {}
|
6
|
+
|
7
|
+
class<<self
|
8
|
+
attr_accessor :nodes
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :durations, :lost, :host
|
12
|
+
|
13
|
+
def initialize(ping)
|
14
|
+
@durations ||= []
|
15
|
+
@lost ||= 0
|
16
|
+
@host = ping.host
|
17
|
+
if (ping_duration = ping.duration)
|
18
|
+
@durations << (ping_duration * 1000).round(PRECISION)
|
19
|
+
else
|
20
|
+
@lost += 1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def store
|
25
|
+
if stored?
|
26
|
+
stored.durations += durations
|
27
|
+
stored.lost += lost
|
28
|
+
else
|
29
|
+
self.class.nodes[host] = self
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def stored?
|
34
|
+
stored ? true : false
|
35
|
+
end
|
36
|
+
|
37
|
+
def stored
|
38
|
+
self.class.nodes[host]
|
39
|
+
end
|
40
|
+
|
41
|
+
def hash
|
42
|
+
host.hash
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/zombie_check/version.rb
CHANGED
data/lib/zombie_check.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "zombie_check/core_ext/ennumerable"
|
3
3
|
require "zombie_check/version"
|
4
|
+
require "zombie_check/ping"
|
4
5
|
require "zombie_check/ping/checker"
|
5
6
|
require "zombie_check/ping/checker_report"
|
7
|
+
require "zombie_check/ping/host_stat"
|
6
8
|
require "net/ping"
|
7
9
|
|
8
10
|
module ZombieCheck
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zombie_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kvokka
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- ".rubocop_todo.yml"
|
81
81
|
- ".travis.yml"
|
82
82
|
- Gemfile
|
83
|
+
- LICENSE
|
83
84
|
- README.md
|
84
85
|
- Rakefile
|
85
86
|
- bin/console
|
@@ -88,8 +89,10 @@ files:
|
|
88
89
|
- hosts.txt
|
89
90
|
- lib/zombie_check.rb
|
90
91
|
- lib/zombie_check/core_ext/ennumerable.rb
|
92
|
+
- lib/zombie_check/ping.rb
|
91
93
|
- lib/zombie_check/ping/checker.rb
|
92
94
|
- lib/zombie_check/ping/checker_report.rb
|
95
|
+
- lib/zombie_check/ping/host_stat.rb
|
93
96
|
- lib/zombie_check/version.rb
|
94
97
|
- zombie_check.gemspec
|
95
98
|
homepage: https://github.com/kvokka/zombie_check
|