Skip to content

Instantly share code, notes, and snippets.

@apeckham
Created June 13, 2012 22:46
Show Gist options
  • Save apeckham/2926975 to your computer and use it in GitHub Desktop.
Save apeckham/2926975 to your computer and use it in GitHub Desktop.
running librato's statsd chef recipe on ec2 with knife-solo, and sending data from Rails
# http://cloud.ubuntu.com/ami/
ec2-run-instances ami-a29943cb -k $KEYPAIR -t t1.micro --block-device-mapping /dev/sda1=:50
ec2-describe-instances i-XXXXXXX
# allow heroku to access UDP on 8125: https://devcenter.heroku.com/articles/external-services
ec2-authorize default -P udp -p 8125 -u 098166147350 -o default
# ^^ not sure if this actually worked, might have to open that port to everywhere
gem install knife-solo
# or gem update knife-solo; gem list knife-solo to see old versions; gem remove knife-solo -v VERSION to remove an old version
knife kitchen mychefrepo
cd mychefrepo
knife prepare ubuntu@$REMOTE_HOST
cat <<END >nodes/$REMOTE_HOST.json
{
"run_list": [
"statsd"
],
"statsd": {
"backends": {
"statsd-librato-backend": ""
},
"extra_config": {
"librato": {
"email": "xvkhj@zxjkhxvckhj.com",
"token": "fill in from https://metrics.librato.com/account"
}
}
}
}
END
git clone https://github.com/librato/statsd-cookbook.git cookbooks/statsd
git clone https://github.com/mdxp/nodejs-cookbook.git cookbooks/nodejs
git clone https://github.com/opscode-cookbooks/build-essential.git cookbooks/build-essential
ls cookbooks | while read line; do pushd cookbooks/$line && git pull && popd; done
knife cook ubuntu@$REMOTE_HOST
vim /etc/statsd/config.js
add console backend:
"backends": [
"./backends/graphite",
"./backends/console",
"statsd-librato-backend"
],
restart statsd
tail -F /var/log/statsd.log
# in config/initializers
Statsd.logger = Rails.logger
$statsd = Statsd.new(ENV['STATSD_HOST'] || "localhost")
$statsd.increment "app.initialize"
ActiveRecord::Base.after_create do |record|
$statsd.increment "db.#{record.class.table_name}.create"
end
# in Gemfile:
# gem 'statsd-ruby', git: 'git://github.com/github/statsd-ruby.git', require: 'statsd'
# on the remote machine
cat /etc/statsd/config.js
ps auxw | grep statsd
status statsd
watch -n 1 'echo timers | nc 0 8126; echo stats | nc 0 8126; echo counters | nc 0 8126'
echo timers | nc 0 8126
echo stats | nc 0 8126
echo counters | nc 0 8126
echo 'glork:320|ms' | nc -q1 -u localhost 8125
# shows up on https://metrics.librato.com/metrics/glork.90
tail -F /var/log/statsd.log
# to remove dead metrics, either restart statsd or you can access the statsd console (telnet localhost 8126) and use delcounters or deltimers or delgauges to remove the metric in question from being tracked.
# ^^ thanks Matt @ Librato
# watch incoming udp packets
tcpdump -A "port 8125" | grep '|'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment