class CF::App::Stats

Public Instance Methods

percentage(num, low = 50, mid = 70) click to toggle source
# File lib/cf/cli/app/stats.rb, line 49
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() click to toggle source
# File lib/cf/cli/app/stats.rb, line 9
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])}",
            "#{usage(usage[:mem], stats[:mem_quota])}",
            "#{usage(usage[:disk], stats[:disk_quota])}"
          ]
        else
          [idx, c("n/a", :neutral)]
        end
      end
    })
end
usage(used, limit) click to toggle source
# File lib/cf/cli/app/stats.rb, line 62
def usage(used, limit)
  "#{b(human_size(used))} of #{b(human_size(limit, 0))}"
end