def health
      if state == "STARTED"
        healthy_count = running_instances
        expected = total_instances

        if expected > 0
          ratio = healthy_count / expected.to_f
          if ratio == 1.0
            "RUNNING"
          else
            "#{(ratio * 100).to_i}%"
          end
        else
          "N/A"
        end
      else
        state
      end
    rescue CFoundry::StagingError, CFoundry::NotStaged
      "STAGING FAILED"
    end
def health
      if state == "STARTED"
        healthy_count = running_instances
        expected = total_instances

        if expected > 0
          ratio = healthy_count / expected.to_f
          if ratio == 1.0
            "RUNNING"
          else
            "#{(ratio * 100).to_i}%"
          end
        else
          "N/A"
        end
      else
        state
      end
    rescue CFoundry::StagingError, CFoundry::NotStaged
      "STAGING FAILED"
    end
Determine application health.

 If all instances are running, returns "RUNNING". If only some are
 started, returns the percentage of them that are healthy.

 Otherwise, returns application's status.