Module: ElbPing::CLI
- Defined in:
- lib/elbping/cli.rb
Constant Summary collapse
- OPTIONS =
Set up default options
{}
- PARSER =
Build parser for command line options
OptionParser.new do |opts| opts. = "Usage: #{$0} [options] <elb hostname>" opts.on("-N NAMESERVER", "--nameserver NAMESERVER", "Use NAMESERVER to perform DNS queries (default: #{OPTIONS[:nameserver]})") do |ns| OPTIONS[:nameserver] = ns end opts.on("-L LENGTH", "--verb-length LENGTH", Integer, "Use verb LENGTH characters long (default: #{OPTIONS[:verb_len]})") do |n| OPTIONS[:verb_len] = n end opts.on("-W SECONDS", "--timeout SECONDS", Integer, "Use timeout of SECONDS for HTTP requests (default: #{OPTIONS[:timeout]})") do |n| OPTIONS[:timeout] = n end opts.on("-w SECONDS", "--wait SECONDS", Integer, "Wait SECONDS between pings (default: #{OPTIONS[:wait]})") do |n| OPTIONS[:wait] = n end opts.on("-c COUNT", "--count COUNT", Integer, "Ping each node COUNT times (default: #{OPTIONS[:count]})") do |n| OPTIONS[:count] = n end end
Class Method Summary collapse
-
.main ⇒ Object
Main entry point of the program.
-
.usage ⇒ Object
Parse options.
Class Method Details
.main ⇒ Object
Main entry point of the program
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/elbping/cli.rb', line 53 def self.main PARSER.parse!(ARGV) rescue usage run = true # Set up summary objects total_summary = { :reqs_attempted => 0, :reqs_completed => 0, :latencies => [], } node_summary = {} # Catch ctrl-c trap("SIGINT") { #ElbPing::Display.summary(total_summary, node_summary) #exit! run = false } if ARGV.size < 1 usage end target = ARGV[0] begin nodes = ElbPing::Resolver.find_elb_nodes(target, OPTIONS[:nameserver]) rescue puts "Error querying DNS for #{target} (NS: #{OPTIONS[:nameserver]})" exit(false) end if nodes.size < 1 puts "Could not find any ELB nodes, no pings sent." exit(false) end nodes.each { |node| node_summary[node] = total_summary.clone } iteration = 0 while (OPTIONS[:count] < 1 || iteration < OPTIONS[:count]) && run sleep OPTIONS[:wait] if iteration > 0 nodes.map { |node| total_summary[:reqs_attempted] += 1 node_summary[node][:reqs_attempted] += 1 status = ElbPing::HttpPinger.ping_node(node, OPTIONS[:verb_len], OPTIONS[:timeout]) unless status[:code] == :timeout total_summary[:reqs_completed] += 1 total_summary[:latencies] += [status[:duration]] node_summary[node][:reqs_completed] += 1 node_summary[node][:latencies] += [status[:duration]] end ElbPing::Display.response(status) } iteration += 1 end ElbPing::Display.summary(total_summary, node_summary) end |
.usage ⇒ Object
Parse options
47 48 49 50 |
# File 'lib/elbping/cli.rb', line 47 def self.usage puts PARSER.help exit(false) end |