-
-
Save adilwali/e7ade9b9b8014a9b254c to your computer and use it in GitHub Desktop.
This file contains 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 characters
=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 | |
when 1 | |
if current > 1 | |
(current.to_i - 1) | |
else | |
1 | |
end | |
else | |
(current + threshold_value) | |
end | |
puts "set: #{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