3 class Application::Ping<Application
4 description "Ping all nodes"
7 :description => "Shows a graph of ping distribution",
8 :arguments => ["--graph", "-g"],
12 # Convert the times structure into a array representing
13 # buckets of responses in 50 ms intervals. Return a small
14 # sparkline graph using UTF8 characters
16 return "" unless configuration[:graph] || Config.instance.pluginconf["rpc.graph"]
18 ticks=%w[▁ ▂ ▃ ▄ ▅ ▆ ▇]
22 # round each time to its nearest 50ms
23 # and keep a count for each 50ms
24 resp_times.each do |time|
25 time = Integer(time + 50 - (time % 50))
30 # set the 50ms intervals that saw no traffic to 0
31 ((histo.keys.max - histo.keys.min) / 50).times do |i|
32 time = (i * 50) + histo.keys.min
33 histo[time] = 0 unless histo[time]
36 # get a numerically sorted list of times
37 histo = histo.keys.sort.map{|k| histo[k]}
39 range = histo.max - histo.min
40 scale = ticks.size - 1
41 distance = histo.max.to_f / scale
44 tick = (val / distance).round
52 client = MCollective::Client.new(options[:config])
53 client.options = options
58 client.req("ping", "discovery") do |resp|
59 times << (Time.now.to_f - start) * 1000
61 puts "%-40s time=%.2f ms" % [resp[:senderid], times.last]
64 puts("\n\n---- ping statistics ----")
67 sum = times.inject(0){|acc,i|acc +i}
68 avg = sum / times.length.to_f
70 puts "%d replies max: %.2f min: %.2f avg: %.2f %s" % [times.size, times.max, times.min, avg, spark(times)]
72 puts("No responses received")