Last active
October 21, 2020 22:24
-
-
Save cstump/ef8c3b8d772ec0287002b05377c1e1d0 to your computer and use it in GitHub Desktop.
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 'ap' | |
| require 'pry' | |
| require 'platform-api' | |
| token = 'c' # Create token as seen at https://github.com/heroku/platform-api#a-real-world-example | |
| heroku = PlatformAPI.connect_oauth(token) | |
| apps = heroku.app.list | |
| app_names = apps.map { |app| app['name'] unless app['name'].include?('-pr-') }.compact | |
| dynos = {} | |
| total_dynos = 0 | |
| # organize dynos | |
| app_names.each do |name| | |
| app_formation = heroku.formation.list(name) | |
| app_formation.each do |formation| | |
| quantity = formation['quantity'] | |
| next if quantity.zero? | |
| dyno_size = formation['size'] | |
| formation_id = "#{name}:#{formation['type']}" | |
| dynos[dyno_size] ||= {} | |
| dynos[dyno_size][formation_id] = quantity | |
| end | |
| end | |
| # report on dynos | |
| dynos.each do |k,v| | |
| sum = v.values.sum | |
| total_dynos += sum | |
| puts "#{sum} #{k}\n" | |
| end | |
| puts "\n#{total_dynos} dynos total\n\n" | |
| ap dynos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment