Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding additional metrics to Dropwizard

How do I go about adding custom metrics to the default stuff that Dropwizard provides on the admin port (8081)? I can't find anything in the documentation apart from adding health checks. I'd quite like to incorporate some stats retrieved from MongoDB, and would rather keep it with the admin resources on 8081 than create a custom metrics page on port 8080.

like image 721
johncowie Avatar asked Mar 26 '13 11:03

johncowie


1 Answers

If you want your metrics to show up with the metrics servlet that's included in your Dropwizard project, you must use the same MetricRegistry object that the servlet used and register your metrics into it.

You can get the correct MetricRegistry instance from the Environment in your application; or from the Bootstrap object that's passed to its initilaize method during startup.

The Dropwizard documentation fails to mention the scope of the MetricRegistry and the objects it contains. It implies that you just create your own MetricRegistry. That'll work fine for the stand alone "getting started" application, but the document is about adding metrics to an existing Dropwizard application, not a new, standalone application.

like image 134
MikeB Avatar answered Nov 15 '22 22:11

MikeB