Capturing Metrics Challenge part 1 – Dropwizard and Graphite
Performance metrics are key for monitoring and maintaining any system. As part of a prototype exercise, I had been busy writing some custom components to handle this. It had basically involved writing some components on Dropwizard that consume messages on RabbitMQ and write them into a MongoDB collection. There was a lot more complexity involved, as messages could arrive in any order, and I also needed to expose an API that would show summary information by service type etc.
Anyway, that was all exciting but deep down it felt like the wrong approach and too much custom coding involved. Looking around, there are a number of options that utilise configuration options in Dropwizard, or existing libraries.
The initial simple challenge was to show how you can expose performance metrics from Dropwizard and I chose Graphite as a monitoring tool to collect the data and render graphs on demand.
The first challenge was how to install Graphite locally on Mac OS. Graphite has a whole load of dependencies e.g. Graphite Web, Carbon, Whisper, Ceres. This was going to be a pain, but luckily there is a handy Docker image for Graphite and Statsd. Firing up Boot2Docker, I had a running instance of Graphite in no time at all.
Configuring Dropwizard to output metrics to Graphite was just as simple. All it took was:
1) Adding the following config to the yaml file:
metrics:
reporters:
- type: graphite
host: localhost
port: 8080
prefix:
2) Adding the @Timed annotation the relevant resources
3) Adding the ‘dropwizard-metrics-graphite’ dependency to the maven POM file