forked from choria-legacy/marionette-collective
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mc-ping
executable file
·45 lines (33 loc) · 1 KB
/
mc-ping
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env ruby
require 'mcollective'
oparser = MCollective::Optionparser.new({:verbose => true})
options = oparser.parse{|parser, options|
parser.define_head "Pings all hosts and report their names and some stats"
}
begin
client = MCollective::Client.new(options[:config])
client.options = options
start = Time.now.to_f
times = []
client.req("ping", "discovery") do |resp|
times << (Time.now.to_f - start) * 1000
if options[:verbose]
printf("%-40s time=%.2f ms\n", resp[:senderid], times.last)
else
printf(".")
end
end
client.disconnect
rescue Exception => e
STDERR.puts "Could not call remote agent: #{e}"
exit 1
end
puts("\n\n---- ping statistics ----")
if times.size > 0
sum = times.inject(0){|acc,i|acc +i}
avg = sum / times.length.to_f
printf("%d replies max: %.2f min: %.2f avg: %.2f\n", times.size, times.max, times.min, avg)
else
puts("No responses received")
end
# vi:tabstop=4:expandtab:ai