Last active
September 23, 2016 15:56
-
-
Save saliceti/cda2296d7703cde75c7340d16ebcb41f to your computer and use it in GitHub Desktop.
CF usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 = quotas.select { |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 | |
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 | |
puts "Memory actually used by apps: #{apps_used_memory} (#{apps_used_memory/1024} GB)" | |
puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment