Skip to content

Instantly share code, notes, and snippets.

@raindeerr
Forked from robotmay/dashing-heroku.md
Last active November 29, 2016 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raindeerr/e8c7cc339563af3e8d62dae3ec0b1657 to your computer and use it in GitHub Desktop.
Save raindeerr/e8c7cc339563af3e8d62dae3ec0b1657 to your computer and use it in GitHub Desktop.
Heroku jobs for Dashing. Returns the number of active dynos for each process type (including custom processes). Set your Heroku keys as environment variables.

Add the following to your Gemfile:

gem 'platform-api'

Put heroku-dynos.rb in your jobs folder and add the contents of heroku.html into your layout.

require 'platform-api'
key = ENV['HEROKU_API_KEY']
app_name = ENV['HEROKU_APP_NAME']
heroku = PlatformAPI.connect_oauth(key)
SCHEDULER.every '15s', :first_in => 0 do |job|
dynos = heroku.dyno.list(app_name)
process_counts = dynos.reduce({}) do |hash, dyno|
process, i = dyno['name'].split(".")
hash[process] ||= 0
hash[process] += 1
hash
end
process_counts.each do |ps, n|
send_event("heroku_dyno_#{ps}", { value: n })
end
end
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="heroku_dyno_web" data-view="Meter" data-title="Web Dynos" data-min="0" data-max="10"></div>
</li>
<li data-row="1" data-col="2" data-sizex="1" data-sizey="1">
<div data-id="heroku_dyno_worker" data-view="Meter" data-title="Workers" data-min="0" data-max="10"></div>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment