Class: MCollective::Application::Ping

Inherits:
MCollective::Application show all
Defined in:
lib/mcollective/application/ping.rb

Overview

rubocop:disable Style/ClassAndModuleChildren

Instance Attribute Summary

Attributes inherited from MCollective::Application

#options

Instance Method Summary collapse

Methods inherited from MCollective::Application

[], []=, #application_cli_arguments, #application_description, #application_failure, application_options, #application_options, #application_parse_options, #application_usage, #clioptions, #configuration, description, #disconnect, exclude_argument_sections, external, external_help, #external_help, #external_main, #halt, #halt_code, #help, intialize_application_options, option, #rpcclient, #run, usage, #validate_cli_options, #validate_option

Methods included from RPC

const_missing, discovered, #empty_filter?, #printrpc, #printrpcstats, #rpcclient, #rpcoptions, stats

Instance Method Details

#mainObject



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
# File 'lib/mcollective/application/ping.rb', line 5

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