Search code examples
javadropwizardmetrics

how can I collect all dropwizard metrics together in a same Reporter?


I am working in a Dropwizard app. At the moment, with dropwizard some metrics are included in the /admin endpoint

So, if you set @Timed to your controller, it will automatically appear there.

The problem is when want to add custom metrics.

I checked this documentation:

https://metrics.dropwizard.io/3.1.0/getting-started/

So I created my own registry and added my own timer.

I see it in the console reporter, working quite well.

The problem is that I dont see it as part of the /admin, is it possible to add it into one single Metrics "group"?

I did something like this

on the constructor:

 static final MetricRegistry metrics = new MetricRegistry();
 startReport();
 Meter requests = metrics.meter("requests");

and at my controller:

requests.mark

Like I said, it works and I see it reflected in my console reporter, but I am not able to see it at /admin or viceversa (at the console I only see that metric, like if is a different registry.


Solution

  • The application has its own MetricRegistry, that you can access via environment.metrics(). You have to register you timer in that register.