At dotCloud, we are very happy users of collectd. collectd is a metrics collection daemon, an alternative (much superior, in my opinion) to Munin that you might know. At dotCloud we use collectd to collect system metrics, but it could also be used for business or application oriented metrics quite easily.
collectd is basically a big loop, which read (i.e: collect) and/or write (in a storage backend like RRDs, on the network, etc.) metrics at a configurable interval. collectd is very efficient at that, and since it’s modular, a collectd daemon can be configured to collect metrics, store them or simply route them to other collectd servers using its efficient binary protocol; all of that from a large list of plugins.
However, collectd doesn’t do any graphing at all and you have to use something on top of the storage backend you picked up. So, collectd is fairly easy to set up but getting graphs —the coolest part— ends up being a pain each time. But, there is another project called Graphite, which is good at storing and displaying time-series metrics but cannot collect them. That makes it a great combo with collectd.
Graphite is still a pain to install compared to collectd, but at least you only need to set it up once (whereas you want collectd on each host/container where you collect metrics), but thanks to this Dockerfile, this is a solved issue! And in the process, we added UDP support in Docker since UDP is used by collectd’s network protocol.
So, two things:
- You can now open/redirect UDP ports in Docker containers, e.g: 25826/udp;
- You can now deploy a collectd/Graphite receiver/graphing frontend easily.
If you have Docker (from master, UDP support hasn’t been released yet) installed, you can try that out with:
docker pull lopter/collectd-graphite
docker run lopter/collectd-graphite
Then, using docker ps, write down which port has been assigned to collectd and which one has been assigned to the web interface:
The other ports are for SSH and for Graphite (in case you want to send data to Graphite directly instead of going through collectd).
Install collectd using your favorite package manager, open collectd.conf and add:
Server "<your-docker-host>" "<the-collectd-port-likely-49153>"
Restart collectd and point your browser to http://<your-docker-host>:<the-other-port-in-docker-ps>, and you should see this:
By navigating in the tree on the left, you can start to build your own graphs:
If you want to save configured graphs, you can login into graphite with the username “graphite” and the password “admin”.
I’m very excited about this, because I always wanted to use collectd more, even during development/test phases (collectd can collect metrics down to a one second resolution which makes it interesting for that), but I never did it because of the high cost of setting up the graphing. With Docker I can deploy my own, disposable, collectd/graphite receiver in a few secs and get some insightful infos right away.
The sources for this Docker image are on GitHub, in it you’ll find the Dockerfile, but also the configuration files used for collectd and Graphite, which you might want to tune!