Created
June 13, 2012 22:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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": "[email protected]", | |
"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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim /etc/statsd/config.js | |
add console backend: | |
"backends": [ | |
"./backends/graphite", | |
"./backends/console", | |
"statsd-librato-backend" | |
], | |
restart statsd | |
tail -F /var/log/statsd.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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