Dropwizard

Background

Dropwizard Metrics is a popular solution used by Java developers to capture JVM and application-level metrics from their services. In addition to distributed tracing, OpenCensus also captures application-level metrics from Java services, and interoperability between Dropwizard and OpenCensus has been one of our most asked for Java features.

We have good news: OpenCensus now provides an easy way to export and migrate Dropwizard metrics to OpenCensus, and then on to your backend of choice.

Prerequisites

Assuming, you already have both the OpenCensus and Dropwizard client libraries setup and working inside your application.

Prometheus as our choice of metrics backend: we are picking it because it is free, open source and easy to setup

For assistance setting up Prometheus, Click here for a guided codelab.

We also need to expose the Prometheus endpoint say on address “localhost:8888” in order for Prometheus to scrape our application. Please add the following to our Java code.

privatestaticvoidsetupOpenCensusAndPrometheusExporter()throwsIOException{// Register the Prometheus exporter
PrometheusStatsCollector.createAndRegister();// Run the server as a daemon on address "localhost:8888"
HTTPServerserver=newHTTPServer("localhost",8888,true);}