项目作者: sps

项目描述 :
OpenTSDB Metrics Reporter
高级语言: Java
项目地址: git://github.com/sps/metrics-opentsdb.git
创建时间: 2014-02-14T23:02:45Z
项目社区:https://github.com/sps/metrics-opentsdb

开源协议:Apache License 2.0

下载


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:

  1. @Override
  2. public void run(T configuration, Environment environment) throws Exception {
  3. ...
  4. OpenTsdb opentsdb = OpenTsdb.forService("http://opentsdb/")
  5. .withGzipEnabled(true) // optional: compress requests to tsd
  6. .create();
  7. OpenTsdbReporter.forRegistry(environment.metrics())
  8. .prefixedWith(environment.getName())
  9. .withTags(ImmutableMap.of("other", "tags")) // static tags included with every metric
  10. // .withBatchSize(10) // optional batching. unbounded by default. likely need to tune this.
  11. .build(opentsdb)
  12. .start(15L, TimeUnit.SECONDS); // tune your reporting interval

Tagged Metric Registry

  1. // setup
  2. TaggedMetricRegistry metrics = new TaggedMetricRegistry();
  3. Map<String, String> tags = new HashMap<String, String>();
  4. tags.put("host", "localhost");
  5. tags.put("foo", "bar");
  6. OpenTsdbReporter.forRegistry(metrics)
  7. .withTags(tags)
  8. .withBatchSize(5)
  9. .build(OpenTsdb.forService("http://opentsdb/")
  10. .create())
  11. .start(30L, TimeUnit.SECONDS);
  12. // using metric with tags
  13. Map<String, String> counterTags = new HashMap<String, String>(tags);
  14. counterTags.put("trigger", trigger);
  15. TaggedCounter counter = metrics.taggedCounter("my.tagged.counter", counterTags);
  16. counter.inc();
  • Completely backwords compatible with existing Coda Hale metrics
  • All Coda Hale metrics have a Tagged\ counterpart (e.g. TaggedCounter, TaggedMeter, etc.)
  • Registry can have default tags that can be overridden at the metric level
  • Metrics can have additional tags not in the registry
  • Calling a tagged\ function (e.g. taggedCounter(), taggedMeter(), etc.) on the TaggedMetric registry will perform a get or create operation. If the same type of metric with the same name and tags is already registered in the registry, it will be returned, otherwise it will be created and returned. There is no need to check for name or tag collisions.

The Telnet API is identical to the above, except with

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

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

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