Skip to content

Instantly share code, notes, and snippets.

@robotmay
Last active November 29, 2016 11:59
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save robotmay/5999634 to your computer and use it in GitHub Desktop.
Save robotmay/5999634 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 'heroku-api'

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

<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>
require 'heroku-api'
key = ENV['HEROKU_API_KEY']
app_name = ENV['HEROKU_APP_NAME']
heroku = Heroku::API.new(:api_key => key)
SCHEDULER.every '15s', :first_in => 0 do |job|
ps = heroku.get_ps(app_name)
dynos = ps.body.map { |p| p['process'] }
process_counts = dynos.reduce({}) do |hash, dyno|
process, i = dyno.split(".")
hash[process] ||= 0
hash[process] += 1
hash
end
process_counts.each do |ps, n|
send_event("heroku_dyno_#{ps}", { value: n })
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment