Save Your Dosh
This is a little gem for heroku that automatically scales dynos in your heroku/rails based app.
You obviously have to be on
rails. You also need the New Relic RPM add-on
switched on. It doesn't matter whether you have a free or a pro account on new relic.
Hook it up as a rubygem in your
Make sure you have the following
ENV vars in your heroku config
» heroku config === doshmosh Config Vars ..... APP_NAME: your-heroku-app-name HEROKU_API_KEY: your-heroku-api-key NEW_RELIC_API_KEY: your-new-relic-api-key NEW_RELIC_APP_NAME: your-app-name-on-new-relic NEW_RELIC_ID: your-account-id-on-new-relic ......
It is very likely have you won't already have your APP_NAME and HEROKU_API_KEY in there,
so add them with
heroku config:add APP_NAME=foobar HEROKU_API_KEY=your_api_key.
You can get your Heroku API Key from https://dashboard.heroku.com/account but unfortunately, Heroku's API is currenly on a per-account basis, not a per-application basis.
Once you've done with those, add the
rake save:your:dosh task in heroku's scheduler
and set the minimal timeout of
10 mins. (don't make it less than 6 mins, otherwise
new relic will kick your ass)
You can mangle with the settings by creating a file like that in your rails app
dynos: min: 1 max: 5 threshold: 50 # % of system busyness when we kick in/out a dyno
How It Works
It's pretty simple, every time you kick the
rake save:your:dosh task via cron or scheduler,
it will make a request to the new relic servers for the data on your application busyness. If
it goes over the threshold, it will increase the amount of dynos until reaches the max number
from the config. Otherwise it will try to switch dynos off until reaches the minimal amount.
All the code in this package released under the terms of the MIT license Copyright (C) 2012 Nikolay Nemshilov