Alternative metrics providers

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Alternative metrics providers

cmkimerer
Hello,

I'd like to do some reporting of the Dropwizard metrics to InfluxDb, but I can't seem to find a way to hook into the DropwizardMetricsModule.  I was expecting to be able to do was just to add any arbitrary ScheduledReporter to it, but it doesn't seem possible by looking at the source.  Am I completely off base in how I am approaching the problem?

TIA
rus
Reply | Threaded
Open this post in threaded view
|

Re: Alternative metrics providers

rus
In order to add your own scheduled reporters you just need to get a handle on the metric registry that's created by the DropwizardMetricsModule and pass it in to your reporters constructor.

A good pattern for this is to create your own Ratpack service (ratpack.server.Service) and bootstrap your reporter there

@Singleton
final class MetricsService implements Service {

    private final FooReporter fooReporter;

    @Inject
    MetricsService(MetricRegistry metricRegistry) {
        this.fooReporter = new FooReporter(
            metricRegistry,
            "foo",
            MetricFilter.ALL,
            TimeUnit.SECONDS,
            TimeUnit.MILLISECONDS
        );
    }

    @Override
    public void onStart(StartEvent event) throws Exception {
        fooReporter.start(1, TimeUnit.MINUTES));
    }

    @Override
    public void onStop(StopEvent event) throws Exception {
        fooReporter.stop();
    }

}

If you'd like to add this to the docs that would be awesome :)
rus
Reply | Threaded
Open this post in threaded view
|

Re: Alternative metrics providers

rus
I guess if you are writing the reporter too then you could just bind it with guice and inject the MetricRegistry.  Then in the service you just need to inject your reporter and start/stop it.
Reply | Threaded
Open this post in threaded view
|

Re: Alternative metrics providers

cmkimerer
Thanks for the insight.  I'll try and get a pull request for the docs update within the next week or two.
rus
Reply | Threaded
Open this post in threaded view
|

Re: Alternative metrics providers

rus
Great :)