This python daemon use Heroku official python API and Pingdom API to automatically scale your Heroku app depending on the dyno's load.
You first need to install Heroku API before playing with this script.
Follow the instructions from the Heroku official python API GitHub page to install Heroku library.
The idea is to use Python's PIP to enable the lib in the whole system :
sudo apt-get install python-pip
sudo pip install heroku
In order to use Pingdom API and to plot graphs, heroku-autoscale needs python-simplejson
and python-gnuplot
:
sudo apt-get install python-simplejson python-gnuplot
Heroku-autoscale was created as a standalone daemon. It just scale your app automatically, depending on the parameters you set and the performance of your app facing the traffic.
The daemon will autoscale your app depending on some parameters you can tweak in a config.ini
file (you can copy the sample file config.sample.ini
and fill it with your parameters).
First, copy the sample file into /etc:
sudo mkdir -p /etc/heroku-autoscale/
sudo cp ./config.sample.ini /etc/heroku-autoscale/config.ini
Then, edit your config file and fill it with yout parameters :
sudo vim /etc/heroku-autoscale/config.ini
[HEROKU_INFOS]
api_key: MY_HEROKU_API_KEY
app_name: MY_APP_NAME
[PINGDOM_INFOS]
api_key: MY_PINGDOM_API_KEY
login: MY_PINGDOM_LOGIN
password: MY_PINGDOM_PASSWORD
check_id: MY_PINGDOM_CHECK_ID
[AUTOSCALE_SETTINGS]
min_dynos: 1
max_dynos: 10
response_time_low: 500
response_time_high: 2000
check_frequency: 5
pingdom_check_period: 30
response_time_trend_low: 0.5
response_time_trend_high: 0.5
plot: False
graphs_folder: /tmp
debug: False
Heroku parameters:
api_key
: Your Heroku API keyapp_name
: The name of the Heroku application you want to auto-scale
Pingdom parameters:
api_key
: Your Pingdom API keylogin
: Your Pingdom login (aka your email)password
: Your Pingdom passwordcheck_id
: The ID of the Pingdom check which monitor your application
Autoscale parameters:
min_dynos
: The autoscale app will not scale down the Heroku app under that number of dynosman_dynos
: The autoscale app will not scale up the Heroku app over that number of dynosresponse_time_low
: If the measured response time is below this number, the Heroku app will be scaled upresponse_time_high
: If the measured response time is over this number, the Heroku app will be scaled downcheck_frequency
: The check frequencypingdom_check_period
: The period of time you want to use from Pingdom websiteresponse_time_trend_low
: If the measured response time is between theresponse_time_low
and theresponse_time_high
bounds, the app will loose a dyno if the the coeficent of the linear regression model is under this valueresponse_time_trend_high
: If the measured response time is between theresponse_time_low
and theresponse_time_high
bounds, the app will gain a dyno if the the coeficent of the linear regression model is over this valueplot
: If enabled, each autoscale step will plot a graph with the response times, the average response time, the response time bounds and the linear regression model of the scatter graphgraphs_folder
: The destination of the plotted graphsdebug
: The Heroku app will not be scaleid but the scaling decisions will be made and logged (and eventually the graphs will be plotted). You must have installedpython-gnuplot
to use this feature
This script was designed to be used as a daemon. You must want to have an init.d
script to manage the daemon.
An init.d
script had allready been written for you: heroku-autoscale
Start by editing this file and change the path of the daemon script:
[...]
# !! CHANGE THIS LINE WITH YOUR REAL DEAMON'S PATH !!
DAEMON_EXEC="/home/sylvain/Projets/Heroku/heroku-autoscale/HerokuAutoscaleDaemon.py"
[...]
And then, copy the script into the init.d
folder:
root# cp heroku-autoscale /etc/init.d
Launch heroku-autoscale, forget about manually scale your app!
If you have installed the init.d script:
root# /etc/init.d/heroku-autoscale start
Or if you wanna use the python script directly:
root# python HerokuAutoscaleDaemon.py
You can tweak some parameters, like the UID, GID, logfiles... by adding some args the the command. Type python HerokuAutoscaleDaemon.py --help
to know how to use it.
Just don't forget to monitor your website… Even if I do my best to make this script working, you should keep an eye on the performance of your app, and take control if needed before your app crash due to an auto-scaling error…
Have fun!