Export Dropwizard Metrics to Prometheus

Prometheus, one of the leading open-source monitoring solutions at the moment. It is written in Go, therefore fast and scalable. It is configurable with simple textfiles which makes it easy to be maintained via puppet. It comes with a lot of out of the box clients.

But in the end, how can we get metrics from a java application. Or more detailed, how can we get metrics from a self written java application which already has some kind of metrics collector like the dropwizard metrics? Dropwizard metrics is a popular instrumentation library for the JVM. We wanted to still use these metrics and just also get them into prometheus.

It’s pretty awesome to see that the developers of prometheus thought somehow the same and therefore its just a few lines of code to implement it.

First of all we have to add the simpleclient_dropwizard to our pom.xml.


  io.prometheus
  simpleclient_dropwizard
  0.0.23

And then we can export the metrics to prometheus Defaultregistry.

import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.dropwizard.DropwizardExports;

// Inside an initialisation function.
CollectorRegistry.defaultRegistry.register(new DropwizardExports(metrics));

Be aware that metrics must be a Dropwizard MetricRegistry.

And thats it…

In the end you maybe also want to export your metrics to pick them up with prometheus. How to do that can be seen at the prometheus documentation.

comments powered by Disqus