Skip to content

Instantly share code, notes, and snippets.

@korotovsky
Forked from jgeurts/statsd-graphite-install.sh
Created February 26, 2014 12:20
Show Gist options
  • Save korotovsky/9228560 to your computer and use it in GitHub Desktop.
Save korotovsky/9228560 to your computer and use it in GitHub Desktop.
sudo apt-get install --assume-yes python-software-properties
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install --assume-yes nodejs
sudo apt-get install --assume-yes git
cd /opt && sudo git clone git://github.com/etsy/statsd.git
# StatsD configuration
cat >> /tmp/localConfig.js << EOF
{
graphitePort: 2003
, graphiteHost: "127.0.0.1"
, port: 8125
}
EOF
sudo cp /tmp/localConfig.js /opt/statsd/localConfig.js
# Install upstart and monit to run statsd as a service
sudo apt-get install --assume-yes upstart monit
cat >> /tmp/statsd.conf << EOF
#!upstart
description "Statsd node.js server"
author "statsd install gist"
start on startup
stop on shutdown
script
export HOME="/root"
echo $$ > /var/run/statsd.pid
exec sudo -u www-data /usr/bin/nodejs /opt/statsd/stats.js /opt/statsd/localConfig.js >> /var/log/statsd.log 2> /var/log/statsd.error.log
end script
pre-start script
# Date format same as (new Date()).toISOString() for consistency
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/statsd.log
end script
pre-stop script
rm /var/run/statsd.pid
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/statsd.log
end script
EOF
sudo cp /tmp/statsd.conf /etc/init/statsd.conf
# Configure monit to monitor statsd service
cat >> /tmp/monit.conf << EOF
#!monit
set logfile /var/log/monit.log
check process nodejs with pidfile "/var/run/statsd.pid"
start program = "/sbin/start statsd"
stop program = "/sbin/stop statsd"
EOF
sudo cp /tmp/monit.conf /etc/monit/conf.d/statsd
# Restart monit
sudo /etc/init.d/monit restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment