elbping 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/elbping/cli.rb +27 -10
- metadata +1 -1
data/lib/elbping/cli.rb
CHANGED
@@ -13,7 +13,7 @@ module ElbPing
|
|
13
13
|
OPTIONS = {}
|
14
14
|
OPTIONS[:verb_len] = ENV['PING_ELB_MAXVERBLEN'] || 128
|
15
15
|
OPTIONS[:nameserver] = ENV['PING_ELB_NS'] || 'ns-941.amazon.com'
|
16
|
-
OPTIONS[:count] = ENV['PING_ELB_PINGCOUNT'] ||
|
16
|
+
OPTIONS[:count] = ENV['PING_ELB_PINGCOUNT'] || 0
|
17
17
|
OPTIONS[:timeout] = ENV['PING_ELB_TIMEOUT'] || 10
|
18
18
|
OPTIONS[:wait] = ENV['PING_ELB_WAIT'] || 0
|
19
19
|
|
@@ -21,19 +21,24 @@ module ElbPing
|
|
21
21
|
PARSER = OptionParser.new do |opts|
|
22
22
|
opts.banner = "Usage: #{$0} [options] <elb hostname>"
|
23
23
|
|
24
|
-
opts.on("-N NAMESERVER", "--nameserver NAMESERVER",
|
24
|
+
opts.on("-N NAMESERVER", "--nameserver NAMESERVER",
|
25
|
+
"Use NAMESERVER to perform DNS queries (default: #{OPTIONS[:nameserver]})") do |ns|
|
25
26
|
OPTIONS[:nameserver] = ns
|
26
27
|
end
|
27
|
-
opts.on("-L LENGTH", "--verb-length LENGTH", Integer,
|
28
|
+
opts.on("-L LENGTH", "--verb-length LENGTH", Integer,
|
29
|
+
"Use verb LENGTH characters long (default: #{OPTIONS[:verb_len]})") do |n|
|
28
30
|
OPTIONS[:verb_len] = n
|
29
31
|
end
|
30
|
-
opts.on("-W SECONDS", "--timeout SECONDS", Integer,
|
32
|
+
opts.on("-W SECONDS", "--timeout SECONDS", Integer,
|
33
|
+
"Use timeout of SECONDS for HTTP requests (default: #{OPTIONS[:timeout]})") do |n|
|
31
34
|
OPTIONS[:timeout] = n
|
32
35
|
end
|
33
|
-
opts.on("-w SECONDS", "--wait SECONDS", Integer,
|
36
|
+
opts.on("-w SECONDS", "--wait SECONDS", Integer,
|
37
|
+
"Wait SECONDS between pings (default: #{OPTIONS[:wait]})") do |n|
|
34
38
|
OPTIONS[:wait] = n
|
35
39
|
end
|
36
|
-
opts.on("-c COUNT", "--count COUNT", Integer,
|
40
|
+
opts.on("-c COUNT", "--count COUNT", Integer,
|
41
|
+
"Ping each node COUNT times (default: #{OPTIONS[:count]})") do |n|
|
37
42
|
OPTIONS[:count] = n
|
38
43
|
end
|
39
44
|
end
|
@@ -53,7 +58,17 @@ module ElbPing
|
|
53
58
|
end
|
54
59
|
|
55
60
|
target = ARGV[0]
|
56
|
-
|
61
|
+
begin
|
62
|
+
nodes = ElbPing::Resolver.find_elb_nodes(target, OPTIONS[:nameserver])
|
63
|
+
rescue
|
64
|
+
puts "Error querying DNS for #{target} (NS: #{OPTIONS[:nameserver]})"
|
65
|
+
exit(false)
|
66
|
+
end
|
67
|
+
|
68
|
+
if nodes.size < 1
|
69
|
+
puts "Could not find any ELB nodes, no pings sent."
|
70
|
+
exit(false)
|
71
|
+
end
|
57
72
|
|
58
73
|
# Set up summary objects
|
59
74
|
total_summary = {
|
@@ -70,8 +85,9 @@ module ElbPing
|
|
70
85
|
exit
|
71
86
|
}
|
72
87
|
|
73
|
-
|
74
|
-
|
88
|
+
i = 0
|
89
|
+
while OPTIONS[:count] < 1 || i < OPTIONS[:count]
|
90
|
+
sleep OPTIONS[:wait] if i > 0
|
75
91
|
|
76
92
|
nodes.map { |node|
|
77
93
|
total_summary[:reqs_attempted] += 1
|
@@ -86,8 +102,9 @@ module ElbPing
|
|
86
102
|
end
|
87
103
|
|
88
104
|
ElbPing::Display.response(status)
|
105
|
+
i += 1
|
89
106
|
}
|
90
|
-
|
107
|
+
end
|
91
108
|
ElbPing::Display.summary(total_summary, node_summary)
|
92
109
|
end
|
93
110
|
end
|