/java-dogstatsd-client

a java statsd client library

Primary LanguageJavaOtherNOASSERTION

java-dogstatsd-client

A statsd client library implemented in Java. Allows for Java applications to easily communicate with statsd.

This version is forked from the upstream java-statsd-client project, adding support for Datadog extensions for use with dogstatsd.

This version also adds support for empty or null prefixes, to allow a client to send arbitrary statistic names.

Downloads

The client jar is distributed via maven central, and can be downloaded here.

<dependency>
    <groupId>com.indeed</groupId>
    <artifactId>java-dogstatsd-client</artifactId>
    <version>2.0.16</version>
</dependency>

Usage

import com.timgroup.statsd.StatsDClient;
import com.timgroup.statsd.NonBlockingStatsDClient;

public class Foo {

  private static final StatsDClient statsd = new NonBlockingStatsDClient(
    "my.prefix",                          /* prefix to any stats; may be null or empty string */
    "statsd-host",                        /* common case: localhost */
    8125,                                 /* port */
    new String[] {"tag:value"}            /* Datadog extension: Constant tags, always applied */
  );

  public static final void main(String[] args) {
    statsd.incrementCounter("foo");
    statsd.recordGaugeValue("bar", 100);
    statsd.recordGaugeValue("baz", 0.01); /* Datadog extension: support for floating-point gauges */
    statsd.recordHistogramValue("qux", 15);    /* Datadog extension: histograms */
    statsd.recordHistogramValue("qux", 15.5);  /* ...also floating-point */

    /* expects times in milliseconds
     */
    statsd.recordExecutionTime("bag", 25, "cluster:foo"); /* Datadog extension: cluster tag */
  }
}