elbping 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/lib/elbping/cli.rb CHANGED
@@ -91,8 +91,9 @@ module ElbPing
91
91
  nameserver = OPTIONS[:nameserver]
92
92
  begin
93
93
  nodes = ElbPing::Resolver.find_elb_nodes elb_uri.host, nameserver
94
- rescue
94
+ rescue StandardError => e
95
95
  ElbPing::Display.error "Unable to query DNS for #{elb_uri.host} using #{nameserver}"
96
+ ElbPing::Display.debug e
96
97
  exit(false)
97
98
  end
98
99
 
@@ -116,6 +117,8 @@ module ElbPing
116
117
  ##
117
118
  # Ping each node while tracking requests, responses, and latencies
118
119
  nodes.map { |node|
120
+ break if not run
121
+
119
122
  status = ElbPing::HttpPinger.ping_node(node,
120
123
  elb_uri.port,
121
124
  (elb_uri.path == "") ? "/" : elb_uri.path,
@@ -21,6 +21,17 @@ module ElbPing
21
21
  self.out "ERROR: #{msg}"
22
22
  end
23
23
 
24
+ # Print debug information to the screen
25
+ #
26
+ # Arguments:
27
+ # * exception: (Exception object)
28
+
29
+ def self.debug(exception)
30
+ if ENV["DEBUG"]
31
+ self.out "DEBUG: #{exception.backtrace}"
32
+ end
33
+ end
34
+
24
35
  # Format and display the ping data given a response
25
36
  #
26
37
  # Arguments:
@@ -46,7 +57,8 @@ module ElbPing
46
57
  # * stats: (ElbPing::Stats)
47
58
 
48
59
  def self.summary(stats)
49
- stats.nodes.keys.each { |node|
60
+ pinged_nodes = stats.nodes.keys.select { |n| stats.nodes[n][:requests] > 0 }
61
+ pinged_nodes.each { |node|
50
62
  loss_pct = (stats.node_loss(node) * 100).to_i
51
63
  self.out "--- #{node} statistics ---"
52
64
  self.out "#{stats.nodes[node][:requests]} requests, #{stats.nodes[node][:responses]} responses, #{loss_pct}% loss"
@@ -1,40 +1,6 @@
1
1
 
2
2
  require 'resolv'
3
-
4
- # A TCP-only resolver built from `Resolv::DNS`. See the docs for what it's about.
5
- # http://ruby-doc.org/stdlib-1.9.3/libdoc/resolv/rdoc/Resolv/DNS.html
6
- class TcpDNS < Resolv::DNS
7
- # Override fetch_resource to use a TCP requester instead of a UDP requester. This
8
- # is mostly borrowed from `lib/resolv.rb` with the UDP->TCP fallback logic removed.
9
- def fetch_resource(name, typeclass)
10
- lazy_initialize
11
- request = make_tcp_requester
12
- sends = {}
13
- begin
14
- @config.resolv(name) { |candidate, tout, nameserver, port|
15
- msg = Message.new
16
- msg.rd = 1
17
- msg.add_question(candidate, typeclass)
18
- unless sender = senders[[candidate, nameserver, port]]
19
- sender = senders[[candidate, nameserver, port]] =
20
- requester.sender(msg, candidate, nameserver, port)
21
- end
22
- reply, reply_name = requester.request(sender, tout)
23
- case reply.rcode
24
- when RCode::NoError
25
- yield(reply, reply_name)
26
- return
27
- when RCode::NXDomain
28
- raise Config::NXDomain.new(reply_name.to_s)
29
- else
30
- raise Config::OtherResolvError.new(reply_name.to_s)
31
- end
32
- }
33
- ensure
34
- requester.close
35
- end
36
- end
37
- end
3
+ require 'elbping/tcp_dns.rb'
38
4
 
39
5
  module ElbPing
40
6
  # Handles all DNS resolution and, more specifically, ELB node discovery
@@ -57,10 +23,12 @@ module ElbPing
57
23
  Timeout::timeout(timeout) do
58
24
  TcpDNS.open :nameserver => nameservers, :search => '', :ndots => 1 do |dns|
59
25
  # TODO: Exceptions
60
- resp = dns.getresources target, Resolv::DNS::Resource::IN::A
26
+ resp = dns.getresources target, Resolv::DNS::Resource::IN::ANY
61
27
  end
62
28
  end
63
- resp.map { |r| r.address.to_s }
29
+ if resp
30
+ resp.select { |r| r.respond_to? "address" and r.address }.map { |r| r.address.to_s }
31
+ end
64
32
  end
65
33
  end
66
34
  end
data/lib/elbping/stats.rb CHANGED
@@ -1,19 +1,5 @@
1
1
 
2
- # TODO: Needs unit tests
3
-
4
- # An array for doing some basic stats on latencies (currently only mean)
5
- class LatencyBucket < Array
6
- def sum
7
- self.inject { |sum, el| sum + el} || 0
8
- end
9
-
10
- def mean
11
- i = 0
12
- unless self.size == 0
13
- i = (self.sum.to_f / self.size).to_i
14
- end
15
- end
16
- end
2
+ require 'elbping/latency_bucket.rb'
17
3
 
18
4
  module ElbPing
19
5
  # Tracks the statistics of requests sent, responses received (hence loss) and latency
@@ -102,4 +88,3 @@ module ElbPing
102
88
 
103
89
  end
104
90
  end
105
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elbping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: