Home

Awesome

Metrics OpenTSDB Build Status Coverage Status

A Coda Hale Metrics Reporter.

OpenTsdbReporter allows your application to constantly stream metric values to an opentsdb server via the 2.0 HTTP API or the Telnet API.

This reporter also supports per-metric tags in addition to a global set of tags.

Example Usage

dropwizard 3.0.1 app:

@Override
public void run(T configuration, Environment environment) throws Exception {
...
    OpenTsdb opentsdb = OpenTsdb.forService("http://opentsdb/")
                                      .withGzipEnabled(true) // optional: compress requests to tsd
                                      .create();

    OpenTsdbReporter.forRegistry(environment.metrics())
                    .prefixedWith(environment.getName())
                    .withTags(ImmutableMap.of("other", "tags")) // static tags included with every metric
                    // .withBatchSize(10) // optional batching. unbounded by default. likely need to tune this.
                    .build(opentsdb)
                    .start(15L, TimeUnit.SECONDS); // tune your reporting interval

Tagged Metric Registry

// setup
TaggedMetricRegistry metrics = new TaggedMetricRegistry();
Map<String, String> tags = new HashMap<String, String>();
tags.put("host", "localhost");
tags.put("foo", "bar");

OpenTsdbReporter.forRegistry(metrics)
    .withTags(tags)
    .withBatchSize(5)
	.build(OpenTsdb.forService("http://opentsdb/")
	.create())
	.start(30L, TimeUnit.SECONDS);

// using metric with tags
Map<String, String> counterTags = new HashMap<String, String>(tags);
counterTags.put("trigger", trigger);

TaggedCounter counter = metrics.taggedCounter("my.tagged.counter", counterTags);
counter.inc();

The Telnet API is identical to the above, except with

OpenTsdbTelnet.forService("mycollector.example.com", 4243)

For per-metric tags, encode the tags into the metric name using

Map<String, String> myCounterTags;
String name = OpenTsdbMetric.encodeTagsInName('mycounter', myCounterTags);