Class: EPC::Command::ShowMetricsCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- EPC::Command::ShowMetricsCommand
- Defined in:
- lib/epc/command/show_metrics_command.rb
Constant Summary
Constants inherited from BaseCommand
BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS
Instance Attribute Summary
Attributes inherited from BaseCommand
#client, #klass_name, #object_id, #object_type, #options, #target_id, #target_type
Instance Method Summary collapse
Methods inherited from BaseCommand
#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err
Methods included from PersistentAttributes
#auth_token, #caller_id, #target_url
Constructor Details
This class inherits a constructor from EPC::Command::BaseCommand
Instance Method Details
#execute(args = []) ⇒ Object
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 46 47 48 49 50 51 52 53 |
# File 'lib/epc/command/show_metrics_command.rb', line 4 def execute(args = []) id = args[0] metrics = args[1] if id.nil? say("You must specify the target object id.") say(EPC::Help::COMMAND_USAGES[:show_metrics]) return 1 end if metrics.nil? say("You must specify the metrics to display.") say(EPC::Help::COMMAND_USAGES[:show_metrics]) return 1 end path = "#{CGI.escape(id)}/metrics/#{CGI.escape(metrics)}" opts = [] opts << "start=#{CGI.escape([:start])}" if [:start] opts << "stop=#{CGI.escape([:stop])}" if [:stop] opts << "step=#{CGI.escape([:step])}" if [:step] path += "?#{opts.join('&')}" unless opts.empty? url = "#{EPC::Config::MONITORED_PATH}/#{path}" # todo: why doesn't this auto-follow the redirect? status, response, headers = client.get(url) unless status == 302 say("Request failed: [#{response[:message]}]") return status end status, response, headers = http_client.get(headers[:uri]) unless status.successful? say("Request failed: [#{response[:message]}]") return status end response = JSON.parse(response) if response say response.inspect response.each_pair do |id,v| v.each_pair do |metric, details| say "#{id} #{metric} start: #{details['start']} stop: #{details['stop']} step: #{details['step']}" say(EPC::VerticalBar.new(details['data']).print) end end if @options[:graph] status end |