Skip to content

Instantly share code, notes, and snippets.

Last active Sep 23, 2016
What would you like to do?
CF usage
#!/usr/bin/env ruby
require 'json'
orgs = JSON.load(`cf curl /v2/organizations`)["resources"]
quotas = JSON.load(`cf curl /v2/quota_definitions`)["resources"]
orgs_reserved_memory = 0
apps_reserved_memory = 0
allocated_services = 0
allocated_routes = 0
orgs.each { |org|
quota_id = org["entity"]["quota_definition_guid"]
quota_def = { |quota| quota["metadata"]["guid"] == quota_id }[0]
orgs_reserved_memory += quota_def["entity"]["memory_limit"].to_i
allocated_services += quota_def["entity"]["total_services"].to_i
allocated_routes += quota_def["entity"]["total_routes"].to_i
org_id = org["metadata"]["guid"]
org_apps_reserved_memory=JSON.load(`cf curl /v2/organizations/#{org_id}/memory_usage`)["memory_usage_in_mb"]
apps_reserved_memory += org_apps_reserved_memory.to_i
puts "Memory reserved by apps in org #{org["entity"]["name"]}: #{org_apps_reserved_memory}"
puts "Memory reserved by orgs: #{orgs_reserved_memory} MB (#{orgs_reserved_memory/1024} GB)"
puts "Memory reserved by apps: #{apps_reserved_memory} MB (#{apps_reserved_memory/1024} GB)"
puts "Allocated services: #{allocated_services}"
puts "Allocated routes: #{allocated_routes}"
apps_used_memory = 0
apps = JSON.load(`cf curl /v2/apps`)["resources"]
apps.each { |app|
apps_used_memory += app["entity"]["memory"].to_i
puts "Memory actually used by apps: #{apps_used_memory} (#{apps_used_memory/1024} GB)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment