Skip to content

Instantly share code, notes, and snippets.

@mataki
Created December 2, 2010 06:33
Show Gist options
  • Select an option

  • Save mataki/724890 to your computer and use it in GitHub Desktop.

Select an option

Save mataki/724890 to your computer and use it in GitHub Desktop.
Auto scalling dynos on heroku using NewRelic
require "rubygems"
require 'heroku'
require "heroku/command"
require "newrelic_rpm"
require "new_relic_api"
app_name = "app-name"
new_relic_license_key = "new_relic_license_key"
NewRelicApi.license_key = new_relic_license_key
puts values = NewRelicApi::Account.find(:first).applications.first.threshold_values
puts threshold_value = values.detect{ |v| v.name == "Apdex" }.threshold_value
# heroku = Heroku::Client.new('email', 'password')
heroku = Heroku::Command::Auth.new({}).client
current = heroku.info(app_name)[:dynos].to_i
puts "current: #{current}"
next_dynos = case threshold_value
when 0
1
when 1
if current > 1
(current.to_i - 1)
else
1
end
else
(current + threshold_value)
end
puts heroku.set_dynos(app_name, next_dynos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment