The OpenCensus DropWizard Util for Java provides an easy way to translate Dropwizard metrics to OpenCensus.
Assuming, you already have both the OpenCensus and Dropwizard client libraries setup and working inside your application.
For Maven add to your pom.xml
:
<dependencies> <dependency> <groupId>io.opencensus</groupId> <artifactId>opencensus-contrib-dropwizard</artifactId> <version>0.17.0</version> </dependency> </dependencies>
For Gradle add to your dependencies:
compile 'io.opencensus:opencensus-dropwizard:0.17.0'
import java.util.Collections; public class YourClass { // Create registry for Dropwizard metrics. static final com.codahale.metrics.MetricRegistry codahaleRegistry = new com.codahale.metrics.MetricRegistry(); // Create a Dropwizard counter. static final com.codahale.metrics.Counter requests = codahaleRegistry.counter("requests"); public static void main(String[] args) { // Increment the requests. requests.inc(); // Hook the Dropwizard registry into the OpenCensus registry // via the DropWizardMetrics metric producer. io.opencensus.metrics.Metrics.getExportComponent().getMetricProducerManager().add( new io.opencensus.contrib.dropwizard.DropWizardMetrics( Collections.singletonList(codahaleRegistry))); } }
This section describes how each of the DropWizard metrics translate into OpenCensus metrics.
Given a DropWizard Counter with name cache_evictions
, the following values are reported:
Note: OpenCensus's CUMULATIVE_INT64 type represent monotonically increasing values. Since DropWizard Counter goes up/down, it make sense to report them as OpenCensus GAUGE_INT64.
Given a DropWizard Gauge with name line_requests
, the following values are reported:
Note: For simplicity, OpenCensus uses GAUGE_DOUBLE type for any Number and GAUGE_INT64 type for Boolean values.
Given a DropWizard Meter with name get_requests
, the following values are reported:
Given a DropWizard Histogram with name results
, the following values are reported:
Given a DropWizard Timer with name requests
, the following values are reported: