Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.