Graphite & StatsD
In short, Graphite is a really cool realtime visualization tool that will take your stats and make graphs out of them, allowing you to combine a few stats into one graph or even perform transformation on the data itself.
StatsD is a NodeJS deamon that accepts UDP packages and flushes them to graphite on a predefined interval. Using UDP for this task is an important advantage: UDP is a “send and forget” protocol which means that even if your StatsD daemon is working really slow or is currently down your performance on production wouldn’t be affected at all.
Look at how cool the end result is:
This is actually not Graphite’s default visualization, but one of the many visualization plugins available for it – Graphene. Now, it doesn’t show up on the image, but this is real-time data in 10 seconds resolution, which auto-updates every 10 seconds with some really slick graph transformations. A real treat for the eye.
By now you should be really thrilled about the possibility of having these cool tools integrated into your system. If you end up doing that, you should use the new RubyGem, TraceD.
TraceD makes it easy to report method execution times or number of times a method was called, with minimal clutter to your code base and with single line of code.
First step as always:
gem install traced
TraceD needs a StatsD client to do the reporting. You can use an existing client like statsd-ruby or your own custom client as long as it adheres to the following interface:
For the sake of simplicity, I will use statsd-ruby here.
Let’s define our first method tracer:
some_method is executed, the execution time is sent to your StatsD daemon under the default generated stat name
As you see, it is that clean and easy to monitor your code.
If you’d like to create a different stat name than the default one, you could mention it in your tracing declaration:
By Default, TraceD will only report execution time. If you’d like to also report how many times the method has been executed you can also add this to your tracing declaration:
Of course you can combine both custom stat name and count options in the same declaration:
It is also possible to trace class methods:
*NOTE: you must declare the
statsd_trace after the method declaration.
I strongly encourage you to give all these great tools a shot. It is really easy to set up, almost doesn’t clutter your code and allows you to freely measure everything in your system.