I am creating a Dropwizard Bundle to be reused across all my microservices. One of the things I would like to standardize on is the MetricRegistry each service uses.
It would be great if I could I could configure each service to use the same MetricRegistry by simply adding my bundle on init, so something like:
class Microservice1 extends Application<Microservice1Config> {
@Override
void initialize(Bootstrap<Microservice1Config> cfg) {
// Boom! Standardized metrics/reporters configured and initialized!
bootstrap.addBundle(new MyBundle())
}
}
The problem is that the Bundle API doesn't seem to be conducive to this type of behavior:
class MyBundle implements Bundle {
MetricRegistry metricRegistry
@Override
void initialize(Bootstrap bootstrap) {
}
@Override
void run(Environment environment) {
environment.jersey().register(???)
}
}
Since the register(...) method doesn't register metricRegistry as a JAX-RS resource, I'm at a loss as to how to wire things up so that this metricRegistry is used for all metrics throughout the entire microservice. Ideas?
Update
What I'm looking for is where to put the following:
MetricRegistry metricRegistry = new MetricRegistry()
Slf4jReporter slf4jReporter = Slf4jReporter.forRegistry(metricRegistry)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.SECONDS)
.build()
slf4jReporter.start(5, TimeUnit.SECONDS)