statsd and graphite quickly with docker
Disclaimer: This guide assumes you know what statsd and graphite are, and that you know how to use docker.
I needed to record some stats which would be collected with statsd then pushed to librato, but I wanted to get everything working locally before deploying it to the production infrastructre. I had never actually used statsd before, but a quick search on docker hub pointed me in the direction of this docker image which looked like it would do everything I needed.
pull down the image and start a container:
docker pull hopsoft/graphite-statsd
docker run -d --name graphite -p 80:80 -p 2003:2003 -p 8125:8125/udp hopsoft/graphite-statsd
you can push data into statsd by simply piping data into it via udp. I use ruby, but you should be able to understand what I’m doing and convert it to whatever technology you use.
UDPSocket.new.send('test:1|g', 0, 'localhost', '8125')
If you use something like boot2docker or docker-machine to host your docker server, you will need to change “localhost” to the address of that machine.
At this point you should launch the graphite dashboard and see if the data you sent shows up.
open “http://localhost:80” in your web browser (again, if you use another host for docker, use that). you should see something similar to this:
Select “stats” then “stats.gauges” then “stats.gauges.test” and you should see a graph appear in the lower part of the screen.
If you send an updated value you will see the graph updating with the new value.
UDPSocket.new.send('test:2|g', 0, 'localhost', '8125')
Thats really all there is to it.