Created
December 2, 2010 06:33
-
-
Save mataki/724890 to your computer and use it in GitHub Desktop.
Revisions
-
mataki revised this gist
Dec 9, 2010 . 1 changed file with 22 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,39 @@ =begin Need to install gems heroku, newrelic_rpm $ gem install heroku newrelic_rpm Set your apps setting app_name : heroku's app_name of auto scaling license_key : NewRelic api key. You can get heroku's NewRelic admin console. "App setting" and "Agent configuration" execute with cron every minutes $ ruby ./adjust_dynos_with_newrelic.rb =end require "rubygems" require 'heroku' require "heroku/command" require "newrelic_rpm" require "new_relic_api" # setup config app_name = "app_name" license_key = "license_key" # get NewRelic data NewRelicApi.license_key = license_key puts values = NewRelicApi::Account.find(:first).applications.first.threshold_values threshold_value = values.detect{ |v| v.name == "Apdex" }.threshold_value puts "threshould_value: #{threshold_value}" # get Heroku data heroku = Heroku::Command::Auth.new({}).client current = heroku.info(app_name)[:dynos].to_i puts "current: #{current}" # set Heroku dyno next_dynos = case threshold_value when 0 1 @@ -30,4 +46,4 @@ else (current + threshold_value) end puts "set: #{heroku.set_dynos(app_name, next_dynos)}" -
mataki created this gist
Dec 2, 2010 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ 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)