Class: VMC::App::Stats
- Defined in:
- lib/vmc/cli/app/stats.rb
Instance Method Summary collapse
Methods inherited from Base
#app_status, #human_mb, #human_size, #megabytes, #memory_choices, #state_color
Methods inherited from CLI
#check_logged_in, #check_target, #client, client, client=, #client_target, #color_enabled?, #default_action, #ensure_config_dir, #err, #execute, #fail, #force?, #invalidate_client, #log_error, #name_list, #no_v2, #one_of, #precondition, #quiet?, #remove_target_info, #sane_target_url, #save_target_info, #save_targets, #set_target, #table, #target_file, #target_info, #targets_info, #tokens_file, #user_colors, #v2?, #verbose?
Methods included from Spacing
#indented, #justify, #line, #lines, #quiet?, #spaced, #start_line, #tabular, #text_width, #trim_escapes
Methods included from Interactive
#ask, #handler, #input_state, #list_choices, #prompt, #show_default
Instance Method Details
#percentage(num, low = 50, mid = 70) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vmc/cli/app/stats.rb', line 51 def percentage(num, low = 50, mid = 70) color = if num <= low :good elsif num <= mid :warning else :bad end c(format("%.1f\%", num), color) end |
#stats ⇒ Object
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 |
# File 'lib/vmc/cli/app/stats.rb', line 10 def stats app = input[:app] stats = with_progress("Getting stats for #{c(app.name, :name)}") do |s| begin app.stats rescue CFoundry::StatsError s.fail do err "Application #{b(app.name)} is not running." return end end end line unless quiet? table( %w{instance cpu memory disk}, stats.sort_by { |idx, _| idx.to_i }.collect { |idx, info| idx = c("\##{idx}", :instance) if info[:state] == "DOWN" [idx, c("down", :bad)] else stats = info[:stats] usage = stats[:usage] if usage [ idx, "#{percentage(usage[:cpu])} of #{b(stats[:cores])} cores", "#{usage(usage[:mem] * 1024, stats[:mem_quota])}", "#{usage(usage[:disk], stats[:disk_quota])}" ] else [idx, c("n/a", :neutral)] end end }) end |
#usage(used, limit) ⇒ Object
64 65 66 |
# File 'lib/vmc/cli/app/stats.rb', line 64 def usage(used, limit) "#{b(human_size(used))} of #{b(human_size(limit, 0))}" end |