STATSD

by customerio
13 deployments · 3 still active · last rev. 4 years ago

Sets up statsd and graphite.

Compatible with: No distros currently supported
						#!/bin/bash
# <UDF name="deploy_user" Label="Name of deployment user" default="deploy" />
# <UDF name="deploy_password" Label="Password for deployment user" />
# <UDF name="new_hostname" Label="Server's hostname" default="appserver" />
# <UDF name="key_url" label="Location of SSH public Key" />

source <ssinclude StackScriptID="1">  # common bash functions
source <ssinclude StackScriptID=123>  # Awesome ubuntu utils script

# Setting up functions

function log {
  echo "### $1 -- `date '+%D %T'`"
}

function create_deployment_user {
  system_add_user $DEPLOY_USER $DEPLOY_PASSWORD "users,sudo"
  system_update_locale_en_US_UTF_8
  cp ~/.gemrc /home/$DEPLOY_USER/
  chown $DEPLOY_USER:$DEPLOY_USER /home/$DEPLOY_USER/.gemrc
}

function system_install_logrotate {
  apt-get -y install logrotate
}

function install_essentials {
  aptitude -y install build-essential libpcre3-dev libssl-dev libcurl4-openssl-dev libreadline5-dev libxml2-dev libxslt1-dev libmysqlclient-dev openssh-server git-core
  good_stuff
}

# Start Installing

log "Updating system..."
system_update
postfix_install_loopback_only
goodstuff

log "Installing essentials"
install_essentials

log "Setting basic security settings"
system_security_fail2ban
system_security_ufw_install
system_security_ufw_configure_basic
system_sshd_permitrootlogin No
system_sshd_passwordauthentication No
system_sshd_pubkeyauthentication Yes
/etc/init.d/ssh restart

log "installing log_rotate"
system_install_logrotate

log "Setting hostname to $NEW_HOSTNAME"
system_update_hostname $NEW_HOSTNAME

log "Creating deployment user $DEPLOY_USER"
create_deployment_user

log "Adding $DEPLOY_USER to sudoers"
cat >> /etc/sudoers <<EOF
$DEPLOY_USER ALL=(ALL) NOPASSWD: ALL
EOF

log "Adding authorized keys"

#Fetch the key
wget $KEY_URL -O ssh_key
mkdir /home/$DEPLOY_USER/.ssh
mv ssh_key /home/$DEPLOY_USER/.ssh/authorized_keys

#Be very blunt about permissions
chown -R $DEPLOY_USER:$DEPLOY_USER /home/$DEPLOY_USER/.ssh/
chmod 640 /home/$DEPLOY_USER/.ssh/authorized_keys 
chmod 750 /home/$DEPLOY_USER/.ssh/

# install git
apt-get install g++ curl libssl-dev apache2-utils
apt-get install git-core
# download the Node source, compile and install it
git clone https://github.com/joyent/node.git /home/$DEPLOY_USER/node
chown -R $DEPLOY_USER:$DEPLOY_USER /home/$DEPLOY_USER/node
cd /home/$DEPLOY_USER/node
./configure
make
make install
# install the Node package manager for later use
cd /home/$DEPLOY_USER
curl http://npmjs.org/install.sh | sh
npm install express
# clone the statsd project
git clone https://github.com/etsy/statsd.git /home/$DEPLOY_USER/statsd
chown -R $DEPLOY_USER:$DEPLOY_USER /home/$DEPLOY_USER/statsd
cd /home/$DEPLOY_USER
# download everything for graphite
mkdir graphite
chown -R $DEPLOY_USER:$DEPLOY_USER /home/$DEPLOY_USER/graphite
cd graphite/
wget "http://pypi.python.org/packages/source/c/carbon/carbon-0.9.9.tar.gz#md5=c97d3bab6d60592daf5146dc1e2fb016"
wget "http://pypi.python.org/packages/source/w/whisper/whisper-0.9.9.tar.gz#md5=8321581e377ac00e1dc33b18bbbb03d6"
wget "http://pypi.python.org/packages/source/g/graphite-web/graphite-web-0.9.9.tar.gz#md5=6e8a6adc930c16f85c3442ce30f49a8f"
tar xzvf whisper-0.9.9.tar.gz 
tar xzvf carbon-0.9.9.tar.gz 
tar xzvf graphite-web-0.9.9.tar.gz
# install whisper - Graphite's DB system
cd whisper-0.9.9
python setup.py install
# install carbon - the Graphite back-end
cd /home/$DEPLOY_USER/graphite/carbon-0.9.9
python setup.py install
cd /opt/graphite/conf
cp carbon.conf.example carbon.conf
# copy the example schema configuration file, and then configure the schema
# see: http://graphite.wikidot.com/getting-your-data-into-graphite
cp storage-schemas.conf.example storage-schemas.conf
# install other graphite dependencies
apt-get install python-cairo
apt-get install python-django
apt-get install memcached
apt-get install python-memcache
apt-get install python-ldap
apt-get install python-twisted
apt-get install apache2 libapache2-mod-python
cd /home/$DEPLOY_USER/graphite/graphite-web-0.9.9
python setup.py install
# copy the graphite vhost example to available sites, edit it to you satisfaction, then link it from sites-enabled
cp example-graphite-vhost.conf /etc/apache2/sites-available/graphite.conf
ln -s /etc/apache2/sites-available/graphite.conf /etc/apache2/sites-enabled/graphite.conf
apache2ctl restart
# I had to create these log files manually 
/opt/graphite/storage/log/webapp
touch info.log
chmod 777 info.log
touch exception.log
chmod 777 exception.log
# make sure to change ownership of the storage folder to the Apache user/group - mine was www-data
chown -R www-data:www-data /opt/graphite/storage/
cd /opt/graphite/webapp/graphite
# copy the local_settings example file to creating the app's settings
# this is where both carbon federation and authentication is configured
cp local_settings.py.example local_settings.py
# run syncdb to setup the db and prime the authentication model (if you're using the DB model)
python manage.py syncdb
# start the carbon cache
cd /opt/graphite/bin/carbon-cache.py start
# copy the the statsd config example to create the config file
# unless you used non-default ports for some other feature of the system, the defaults in the config file are fine
cd /home/$DEPLOY_USER/statsd
cp exampleConfig.js local.js

restartServices

# start statsd
node stats.js local.js