1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
# OpenCensus DropWizard Util for Java
The *OpenCensus DropWizard Util for Java* provides an easy way to translate Dropwizard metrics to
OpenCensus.
## Quickstart
### Prerequisites
Assuming, you already have both the OpenCensus and Dropwizard client libraries setup and working
inside your application.
### Add the dependencies to your project
For Maven add to your `pom.xml`:
```xml
<dependencies>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-contrib-dropwizard5</artifactId>
<version>0.25.0</version>
</dependency>
</dependencies>
```
For Gradle add to your dependencies:
```groovy
compile 'io.opencensus:opencensus-contrib-dropwizard5:0.25.0'
```
### And the following code:
```java
import java.util.Collections;
public class YourClass {
// Create registry for Dropwizard metrics.
static final io.dropwizard.metrics5.MetricRegistry codahaleRegistry =
new io.dropwizard.metrics5.MetricRegistry();
// Create a Dropwizard counter.
Map<String, String> tags = new HashMap<>();
tags.put("tag1", "value1");
tags.put("tag2", "value2");
static final io.dropwizard.metrics5.Counter requests =
codahaleRegistry.counter(new MetricName("requests", tags));
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)));
}
}
```
## Translation to OpenCensus Metrics
This section describes how each of the DropWizard metrics translate into OpenCensus metrics.
### DropWizard Counters
Given a DropWizard Counter with name `cache_evictions`, the following values are reported:
* name: dropwizard5_<initial_metric_name>_<initial_type> (ex: codahale_cache_evictions_counter)
* description: Collected from Dropwizard (metric=<metric_name>, type=<class_name>)
(ex: Collected from Dropwizard (metric=cache_evictions, type=io.dropwizard.metrics5.Counter))
* type: GAUGE_INT64
* unit: 1
* labels: metrics tags are converted to label keys/values
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.
### DropWizard Gauges
Given a DropWizard Gauge with name `line_requests`, the following values are reported:
* name: dropwizard5_<initial_metric_name>_<initial_type> (ex: codahale_line_requests_gauge)
* description: Collected from Dropwizard (metric=<metric_name>, type=<class_name>)
* type: GAUGE_INT64 or GAUGE_DOUBLE
* unit: 1
* labels: metrics tags are converted to label keys/values
Note: For simplicity, OpenCensus uses GAUGE_DOUBLE type for any Number and GAUGE_INT64
type for Boolean values.
### DropWizard Meters
Given a DropWizard Meter with name `get_requests`, the following values are reported:
* name: dropwizard5_<initial_metric_name>_<initial_type> (ex: codahale_get_requests_meter)
* description: Collected from Dropwizard (metric=<metric_name>, type=<class_name>)
* type: CUMULATIVE_INT64
* unit: 1
* labels: metrics tags are converted to label keys/values
### DropWizard Histograms
Given a DropWizard Histogram with name `results`, the following values are reported:
* name: dropwizard5_<initial_metric_name>_<initial_type> (ex: codahale_results_histogram)
* description: Collected from Dropwizard (metric=<metric_name>, type=<class_name>)
* type: SUMMARY
* unit: 1
* labels: metrics tags are converted to label keys/values
### DropWizard Timers
Given a DropWizard Timer with name `requests`, the following values are reported:
* name: dropwizard5_<initial_metric_name>_<initial_type> (ex: codahale_requests_timer)
* description: Collected from Dropwizard (metric=<metric_name>, type=<class_name>)
* type: SUMMARY
* unit:
* labels: metrics tags are converted to label keys/values
|