elbping 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ bundle
2
+ vendor
3
+ *.gem
4
+ *.ign.sh
5
+ Gemfile.lock
6
+ .bundle
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Charles Hooper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,74 @@
1
+ # elbping
2
+
3
+ [![Build Status](https://travis-ci.org/chooper/elbping.png?branch=master)](https://travis-ci.org/chooper/elbping)
4
+
5
+ `elbping` is a tool to ping all of the nodes that make up an Amazon Elastic
6
+ Load Balancer. It only works for ELBs in HTTP and HTTPS mode and works by
7
+ triggering an HTTP 405 (METHOD NOT ALLOWED) error caused when the ELB
8
+ receives a HTTP verb that is too long. This ensures that only the round
9
+ trip time between `elbping` and the elastic load balancer itself is
10
+ being measured.
11
+
12
+ ## Installation
13
+
14
+ Installation is as easy as:
15
+
16
+ ```
17
+ $ gem install elbping
18
+ ```
19
+
20
+ If you want to build a development version or your own branch or fork,
21
+ something like the following will work:
22
+
23
+ ```
24
+ $ git clone git@github.com:chooper/elbping.git
25
+ $ cd elbping
26
+ $ bundle install
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```
32
+ $ elbping
33
+ Usage: ./bin/elbping [options] <elb uri>
34
+ -N, --nameserver NAMESERVER Use NAMESERVER to perform DNS queries (default: ns-941.amazon.com)
35
+ -L, --verb-length LENGTH Use verb LENGTH characters long (default: 128)
36
+ -W, --timeout SECONDS Use timeout of SECONDS for HTTP requests (default: 10)
37
+ -w, --wait SECONDS Wait SECONDS between pings (default: 0)
38
+ -c, --count COUNT Ping each node COUNT times (default: 0)
39
+ $ elbping -c 4 http://test-elb-868888812.us-east-1.elb.amazonaws.com
40
+ Response from 54.243.63.96: code=405 time=210 ms
41
+ Response from 23.21.73.53: code=405 time=189 ms
42
+ Response from 54.243.63.96: code=405 time=191 ms
43
+ Response from 23.21.73.53: code=405 time=188 ms
44
+ Response from 54.243.63.96: code=405 time=190 ms
45
+ Response from 23.21.73.53: code=405 time=192 ms
46
+ Response from 54.243.63.96: code=405 time=187 ms
47
+ Response from 23.21.73.53: code=405 time=189 ms
48
+ --- 54.243.63.96 statistics ---
49
+ 4 requests, 4 responses, 0% loss
50
+ min/avg/max = 187/163/210 ms
51
+ --- 23.21.73.53 statistics ---
52
+ 4 requests, 4 responses, 0% loss
53
+ min/avg/max = 188/189/192 ms
54
+ --- total statistics ---
55
+ 8 requests, 8 responses, 0% loss
56
+ min/avg/max = 188/189/192 ms
57
+ ```
58
+
59
+ ### Configuration
60
+
61
+ In addition to the command line arguments, `elbping` can also be
62
+ configured through the use of environment variables. The following
63
+ enviromment variables are checked and, if no command line argument
64
+ overrides it, its value is used in place of the default:
65
+
66
+ * ``PING_ELB_VERBLEN`` - Size of the HTTP verb to use when pinging an ELB
67
+ * ``PING_ELB_NS`` - DNS server to query the list of ELB nodes from
68
+ * ``PING_ELB_PINGCOUNT`` - The number of pings to send before exiting. Zero means never quit.
69
+ * ``PING_ELB_TIMEOUT`` - The connect and read timeouts to use when sending the request to the ELB node (in seconds)
70
+ * ``PING_ELB_WAIT`` - The amount of time (in seconds) to wait between volleys of pings
71
+
72
+ Note that none of these *need* to be set as `elbping` uses some pretty
73
+ reasonable defaults. See `elbping`'s usage for more details on that.
74
+
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -1,8 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
4
- require 'bundler/setup'
5
-
6
3
  require 'elbping/cli.rb'
7
4
 
8
5
  $stderr.sync = true
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'elbping'
3
+ s.version = '0.0.13'
4
+ s.date = '2013-08-13'
5
+ s.summary = "Small tool to 'ping' the nodes that make up an Amazon Elastic Load Balancer"
6
+ s.description = "elbping is a tool to ping all of the nodes behind an Amazon Elastic Load Balancer. It only works for ELBs in HTTP mode and works by triggering an HTTP 405 (METHOD NOT ALLOWED) error caused when the ELB receives a HTTP verb that is too long."
7
+ s.authors = ["Charles Hooper"]
8
+ s.email = 'chooper@plumata.com'
9
+ s.homepage = 'https://github.com/chooper/elbping'
10
+ s.license = 'MIT'
11
+
12
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.require_paths = ["lib"]
16
+
17
+ s.add_development_dependency "rake", "~> 10.0.4"
18
+
19
+ s.homepage =
20
+ 'https://github.com/chooper/elbping'
21
+ s.license = 'MIT'
22
+ end
@@ -0,0 +1,3 @@
1
+ # Library to discover and ping HTTP and HTTPS ELB nodes
2
+ module ElbPing
3
+ end
@@ -0,0 +1,15 @@
1
+
2
+ # An array for doing some basic stats on latencies (currently only mean)
3
+ class LatencyBucket < Array
4
+ def sum
5
+ self.inject { |sum, el| sum + el} || 0
6
+ end
7
+
8
+ def mean
9
+ if self.size == 0
10
+ 0
11
+ else
12
+ (self.sum.to_f / self.size).to_i
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,44 @@
1
+
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 each_resource(name, typeclass, &proc)
10
+ lazy_initialize
11
+ senders = {}
12
+ requester = nil
13
+ begin
14
+ @config.resolv(name) { |candidate, tout, nameserver, port|
15
+ requester = make_tcp_requester(nameserver, port)
16
+ msg = Message.new
17
+ msg.rd = 1
18
+ msg.add_question(candidate, typeclass)
19
+ unless sender = senders[[candidate, nameserver, port]]
20
+ sender = senders[[candidate, nameserver, port]] =
21
+ requester.sender(msg, candidate, nameserver, port)
22
+ end
23
+
24
+ begin # HACK
25
+ reply, reply_name = requester.request(sender, tout)
26
+ rescue
27
+ return
28
+ end
29
+
30
+ case reply.rcode
31
+ when RCode::NoError
32
+ extract_resources(reply, reply_name, typeclass, &proc)
33
+ return
34
+ when RCode::NXDomain
35
+ raise Config::NXDomain.new(reply_name.to_s)
36
+ else
37
+ raise Config::OtherResolvError.new(reply_name.to_s)
38
+ end
39
+ }
40
+ ensure
41
+ requester.close
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,42 @@
1
+ require 'test/unit'
2
+ require 'elbping/latency_bucket.rb'
3
+
4
+ class TestLatencyBucket < Test::Unit::TestCase
5
+ def test_init
6
+ bucket = nil
7
+ assert_nothing_raised do
8
+ bucket = LatencyBucket.new
9
+ assert_not_nil bucket
10
+ bucket << 1
11
+ bucket << 2
12
+ end
13
+ assert_equal bucket.to_a, [1, 2]
14
+ end
15
+ def test_sum
16
+ bucket = LatencyBucket.new
17
+ bucket << 0
18
+ assert_nothing_raised do
19
+ assert_equal bucket.sum, 0
20
+ end
21
+ bucket << 100
22
+ bucket << 200
23
+ bucket << 300
24
+ bucket << 3
25
+ assert_equal bucket.sum, (0 + 100 + 200 + 300 + 3)
26
+ end
27
+ def test_mean
28
+ bucket = LatencyBucket.new
29
+ bucket << 100
30
+ bucket << 200
31
+ bucket << 300
32
+ bucket << 0
33
+ bucket << 3
34
+ assert_equal bucket.mean, ((100 + 200 + 300 + 0 + 3)/5).to_i
35
+ end
36
+ def test_mean_divide_by_zero
37
+ bucket = LatencyBucket.new
38
+ assert_nothing_raised do
39
+ assert_equal bucket.mean, 0
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,35 @@
1
+ require 'test/unit'
2
+ require 'elbping/pinger.rb'
3
+
4
+ DEFAULT_NODE = ENV['TEST_NODE'] || '127.0.0.1'
5
+ DEFAULT_PORT = ENV['TEST_PORT'] || '80'
6
+ DEFAULT_PATH = ENV['TEST_PATH'] || '/'
7
+ DEFAULT_SSL = ENV['TEST_SSL'] || false
8
+ DEFAULT_VERBLEN = ENV['TEST_VERBLEN'] || 128
9
+ DEFAULT_TIMEOUT = ENV['TEST_TIMEOUT'] || 3
10
+
11
+ class TestHttpPinger < Test::Unit::TestCase
12
+ def test_ping_node
13
+ # ping_node(node, port, path, use_ssl, verb_len, timeout)
14
+ # -> hash
15
+ resp = nil
16
+ assert_nothing_raised do
17
+ resp = ElbPing::HttpPinger.ping_node(
18
+ DEFAULT_NODE,
19
+ DEFAULT_PORT,
20
+ DEFAULT_PATH,
21
+ DEFAULT_SSL,
22
+ DEFAULT_VERBLEN,
23
+ DEFAULT_TIMEOUT)
24
+ end
25
+ # {:code => error |||| response.code,
26
+ # :exception => exc,
27
+ # :node => node,
28
+ # :duration => ((Time.now.getutc - start) * 1000).to_i} # returns in ms
29
+ assert_equal resp.class, Hash
30
+ assert_equal resp[:node], DEFAULT_NODE
31
+ assert_equal resp[:duration].class, Fixnum
32
+ assert_not_equal resp[:code], nil
33
+ end
34
+ end
35
+
@@ -0,0 +1,30 @@
1
+
2
+ require 'test/unit'
3
+ require 'elbping/resolver.rb'
4
+
5
+ DEFAULT_NS = ENV['TEST_NS'] || 'ns-941.amazon.com'
6
+ DEFAULT_GOOD_ELB = ENV['TEST_GOOD_ELB'] || 'test-elb-868888812.us-east-1.elb.amazonaws.com' # feels dirty
7
+
8
+ class TestResolver< Test::Unit::TestCase
9
+ def test_bad_queries
10
+ ["fake.amazonaws.com", "google.com", "nxdomain.asdf"].each { |tgt|
11
+ assert_equal [], ElbPing::Resolver.find_elb_nodes(tgt, DEFAULT_NS)
12
+
13
+ # I think something internal to Resolv is returning nil in tcp mode
14
+ #assert_raise Timeout::Error do
15
+ # ElbPing::Resolver.find_elb_nodes(tgt, DEFAULT_NS)
16
+ #end
17
+ }
18
+ end
19
+
20
+ # This might still fail from time to time :-\ Been seeing lots of failures to connect to AWS DNS
21
+ def test_good_query
22
+ resp = nil
23
+ assert_nothing_raised do
24
+ resp = ElbPing::Resolver.find_elb_nodes(DEFAULT_GOOD_ELB, DEFAULT_NS)
25
+ end
26
+ # I don't actually care what the results are, only that they are a list
27
+ assert_equal resp.class, Array
28
+ end
29
+ end
30
+
@@ -0,0 +1,75 @@
1
+ require 'test/unit'
2
+ require 'elbping/stats.rb'
3
+
4
+ class TestStats < Test::Unit::TestCase
5
+
6
+ STATS_KEYS = [:requests, :responses, :latencies]
7
+ TEST_NODES = ["1.1.1.1", "2.2.2.2", "3.3.3.3"]
8
+
9
+ def test_always_pass
10
+ assert_equal true, true
11
+ end
12
+
13
+ def test_init
14
+ stats = nil
15
+ assert_nothing_raised do
16
+ stats = ElbPing::Stats.new
17
+ end
18
+ assert_not_nil stats
19
+
20
+ # Validate stats.total
21
+ assert_equal stats.total.class, Hash
22
+
23
+ STATS_KEYS.each do |key|
24
+ assert_equal stats.total.keys.include?(key), true
25
+ end
26
+
27
+ # Validate stats.nodes
28
+ assert_equal stats.nodes.class, Hash
29
+ assert_equal stats.nodes.size, 0
30
+ end
31
+
32
+ def test_add_node
33
+ stats = ElbPing::Stats.new
34
+
35
+ TEST_NODES.each do |node|
36
+ assert_nothing_raised do
37
+ stats.add_node node
38
+ end
39
+ assert_equal stats.nodes.keys.include?(node), true
40
+ STATS_KEYS.each do |key|
41
+ assert_equal stats.nodes[node].keys.include?(key), true
42
+ end
43
+ end
44
+ end
45
+
46
+ # TODO: Make this more maintainable
47
+ def test_register
48
+ ping_statuses = [
49
+ {:code => 200, :exception => nil, :node => "1.1.1.1", :duration => 100},
50
+ {:code => 400, :exception => nil, :node => "2.2.2.2", :duration => 100},
51
+ {:code => 405, :exception => nil, :node => "1.1.1.1", :duration => 100},
52
+ {:code => 302, :exception => nil, :node => "2.2.2.2", :duration => 100},
53
+ {:code => :timeout, :exception => nil, :node => "1.1.1.1", :duration => 100},
54
+ {:code => :econnrefused, :exception => nil, :node => "2.2.2.2", :duration => 100},
55
+ {:code => :exception, :exception => "TEST", :node => "1.1.1.1", :duration => 100},
56
+ ]
57
+
58
+ stats = ElbPing::Stats.new
59
+ ping_statuses.each do |status|
60
+ stats.register status
61
+ end
62
+
63
+ assert_equal stats.total[:requests], ping_statuses.size
64
+ assert_equal stats.total[:responses], 4
65
+ assert_equal stats.total[:latencies].size, 4
66
+ assert_equal stats.total_loss, (1 - (4.to_f / ping_statuses.size))
67
+
68
+ assert_equal stats.nodes.size, 2
69
+ assert_equal stats.nodes.keys.include?("1.1.1.1"), true
70
+ assert_equal stats.nodes.keys.include?("2.2.2.2"), true
71
+ assert_equal stats.node_loss("1.1.1.1"), (1 - (2.to_f/4))
72
+ assert_equal stats.node_loss("2.2.2.2"), (1 - (2.to_f/3))
73
+ end
74
+ end
75
+
@@ -0,0 +1,12 @@
1
+ require 'test/unit'
2
+ require 'elbping'
3
+
4
+ # Basic test to ensure testing works at all.
5
+ # Quis custodiet ipsos custodes?
6
+
7
+ class TestTests < Test::Unit::TestCase
8
+ def test_always_pass
9
+ assert_equal true, true
10
+ end
11
+ end
12
+
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.12
4
+ version: 0.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -19,7 +19,7 @@ dependencies:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
21
  version: 10.0.4
22
- type: :runtime
22
+ type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
@@ -37,12 +37,27 @@ executables:
37
37
  extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
+ - .gitignore
41
+ - .travis.yml
42
+ - Gemfile
43
+ - LICENSE
44
+ - README.md
45
+ - Rakefile
46
+ - bin/elbping
47
+ - elbping.gemspec
48
+ - lib/elbping.rb
40
49
  - lib/elbping/cli.rb
41
50
  - lib/elbping/display.rb
51
+ - lib/elbping/latency_bucket.rb
42
52
  - lib/elbping/pinger.rb
43
53
  - lib/elbping/resolver.rb
44
54
  - lib/elbping/stats.rb
45
- - bin/elbping
55
+ - lib/elbping/tcp_dns.rb
56
+ - test/test_latencybucket.rb
57
+ - test/test_pinger.rb
58
+ - test/test_resolver.rb
59
+ - test/test_stats.rb
60
+ - test/test_tests.rb
46
61
  homepage: https://github.com/chooper/elbping
47
62
  licenses:
48
63
  - MIT