-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from ripienaar/83.1
(#83) restore ping as a low level test requirement
- Loading branch information
Showing
1 changed file
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,36 @@ | ||
module MCollective | ||
class Application::Ping < Application # rubocop:disable Style/ClassAndModuleChildren | ||
description "Ping all nodes" | ||
description "Low level network connectivity test" | ||
|
||
external(:command => "choria", :args => ["ping"]) | ||
external_help(:command => "choria", :args => ["ping", "--help"]) | ||
def main | ||
# If the user did not override the default timeout include the discovery timeout | ||
if options[:timeout] == 5 | ||
discovery_timeout = options[:disctimeout] || Config.instance.discovery_timeout || 0 | ||
options[:timeout] = options[:timeout] + discovery_timeout | ||
end | ||
client = MCollective::Client.new(options) | ||
|
||
start = Time.now.to_f | ||
times = [] | ||
|
||
client.req("ping", "discovery") do |resp| | ||
times << (Time.now.to_f - start) * 1000 | ||
|
||
puts "%-40s time=%.2f ms" % [resp[:senderid], times.last] | ||
end | ||
|
||
puts("\n\n---- ping statistics ----") | ||
|
||
if !times.empty? | ||
sum = times.inject(0) {|acc, i| acc + i} | ||
avg = sum / times.length.to_f | ||
|
||
puts "%d replies max: %.2f min: %.2f avg: %.2f" % [times.size, times.max, times.min, avg] | ||
else | ||
puts("No responses received") | ||
end | ||
|
||
halt client.stats | ||
end | ||
end | ||
end |