I was working on an application with DropWizard, and I was having trouble getting my own metrics to show up in the display. The Metrics Getting Started is useful, and it actually showed me what I needed, but didn’t make it obvious enough for me.
What I needed was, in DropWizard Metrics parlance, a “meter.” This gives me performance data over time; basically, every time an event happens, I’d mark
it and thus be able to see how busy the system was in the last minute, the last five minutes, and the last 15 minutes.
I followed the Metrics Getting Started:
- I got a
MetricsRegistry
(by usingnew MetricsRegistry()
) - I created a
Meter
by callingregister.meter(name)
if necessary (and stored theMeter
in a map so I could retrieve it again at will) - I marked an event by calling
Meter.mark()
But at no point was I able to see the meter displayed in the DropWizard servlet.
The reason is because I created my own MetricsRegistry
. One right way to do it is documented; it’s to use SharedMetricRegistries.getDefault();
instead (which gets you a MetricsRegistry
that is displayed automatically).
Note that the DropWizard documentation is not wrong – it just steps past something that most people probably want by default.