• Stars
    star
    170
  • Rank 216,475 (Top 5 %)
  • Language
    Java
  • License
    MIT License
  • Created over 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Java statsd client library

Java DogStatsD Client

CircleCI Build Status Travis Build Status

A DogStatsD client library implemented in Java. Allows for Java applications to easily communicate with the DataDog Agent. The library supports Java 1.7+.

This version was originally forked from java-dogstatsd-client and java-statsd-client but it is now the canonical home for the java-dogstatsd-client. Collaborating with the former upstream projects we have now combined efforts to provide a single release.

See CHANGELOG.md for changes.

Installation

The client jar is distributed via Maven central, and can be downloaded from Maven.

<dependency>
    <groupId>com.datadoghq</groupId>
    <artifactId>java-dogstatsd-client</artifactId>
    <version>4.2.1</version>
</dependency>

Unix Domain Socket support

As an alternative to UDP, Agent v6 can receive metrics via a UNIX Socket (on Linux only). This library supports transmission via this protocol. To use it, pass the socket path as a hostname, and 0 as port.

By default, all exceptions are ignored, mimicking UDP behaviour. When using Unix Sockets, transmission errors trigger exceptions you can choose to handle by passing a StatsDClientErrorHandler:

  • Connection error because of an invalid/missing socket triggers a java.io.IOException: No such file or directory.
  • If DogStatsD's reception buffer were to fill up and the non blocking client is used, the send times out after 100ms and throw either a java.io.IOException: No buffer space available or a java.io.IOException: Resource temporarily unavailable.

Configuration

Once your DogStatsD client is installed, instantiate it in your code:

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

public class DogStatsdClient {

    public static void main(String[] args) throws Exception {

        StatsDClient client = new NonBlockingStatsDClientBuilder()
            .prefix("statsd")
            .hostname("localhost")
            .port(8125)
            .build();

        // use your client...
    }
}

v2.x

Client version v3.x is now preferred over the older client v2.x release line. We do suggest you upgrade to the newer v3.x at your earliest convenience.

The builder pattern described above was introduced with v2.10.0 in the v2.x series. Earlier releases require you use the deprecated overloaded constructors.

DEPRECATED

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

public class DogStatsdClient {

    public static void main(String[] args) throws Exception {

        StatsDClient Statsd = new NonBlockingStatsDClient("statsd", "localhost", 8125);

    }
}

See the full list of available DogStatsD Client instantiation parameters.

Migrating from 2.x to 3.x

Though there are very few breaking changes in 3.x, some code changes might be required for some user to migrate to the latest version. If you are migrating from the v2.x series to v3.x and were using the deprecated constructors, please use the following table to ease your migration to utilizing the builder pattern.

v2.x constructor parameter v2.10.0+ builder method
final Callable addressLookup NonBlockingStatsDClientBuilder addressLookup(Callable val)
final boolean blocking NonBlockingStatsDClientBuilder blocking(boolean val)
final int bufferSize NonBlockingStatsDClientBuilder socketBufferSize(int val)
final String... constantTags NonBlockingStatsDClientBuilder constantTags(String... val)
final boolean enableTelemetry NonBlockingStatsDClientBuilder enableTelemetry(boolean val)
final String entityID NonBlockingStatsDClientBuilder entityID(String val)
final StatsDClientErrorHandler errorHandler NonBlockingStatsDClientBuilder errorHandler(StatsDClientErrorHandler val)
final String hostname NonBlockingStatsDClientBuilder hostname(String val)
final int maxPacketSizeBytes NonBlockingStatsDClientBuilder maxPacketSizeBytes(String... val)
final int processorWorkers NonBlockingStatsDClientBuilder processorWorkers(int val)
final int poolSize NonBlockingStatsDClientBuilder bufferPoolSize(int val)
final int port NonBlockingStatsDClientBuilder port(int val)
final String prefix NonBlockingStatsDClientBuilder prefix(String val)
final int queueSize NonBlockingStatsDClientBuilder queueSize(int val)
final int senderWorkers NonBlockingStatsDClientBuilder senderWorkers(int val)
final Callable telemetryAddressLookup NonBlockingStatsDClientBuilder telemetryAddressLookup(Callable val)
final int telemetryFlushInterval NonBlockingStatsDClientBuilder telemetryFlushInterval(int val)
final int timeout NonBlockingStatsDClientBuilder timeout(int val)

Transport and Maximum Packet Size

As mentioned above the client currently supports two forms of transport: UDP and Unix Domain Sockets (UDS).

The preferred setup for local transport is UDS, while remote setups will require the use of UDP. For both setups we have tried to set convenient maximum default packet sizes that should help with performance by packing multiple statsd metrics into each network packet all while playing nicely with the respective environments. For this reason we have set the following defaults for the max packet size:

  • UDS: 8192 bytes - recommended default.
  • UDP: 1432 bytes - largest possible size given the Ethernet MTU of 1514 Bytes. This should help avoid UDP fragmentation.

These are both configurable should you have other needs:

StatsDClient client = new NonBlockingStatsDClientBuilder()
    .hostname("/var/run/datadog/dsd.socket")
    .maxPacketSizeBytes(16384)  // 16kB maximum custom value
    .build();

Origin detection over UDP and UDS

Origin detection is a method to detect which pod DogStatsD packets are coming from in order to add the pod's tags to the tag list. The DogStatsD client attaches an internal tag, entity_id. The value of this tag is the content of the DD_ENTITY_ID environment variable if found, which is the pod's UID. The Datadog Agent uses this tag to add container tags to the metrics. To avoid overwriting this global tag, make sure to only append to the constant_tags list.

To enable origin detection over UDP, add the following lines to your application manifest

env:
  - name: DD_ENTITY_ID
    valueFrom:
      fieldRef:
        fieldPath: metadata.uid

Aggregation

As of version v2.11.0, client-side aggregation has been introduced in the java client side for basic types (gauges, counts, sets). Aggregation remains unavailable at the time of this writing for histograms, distributions, service checks and events due to message relevance and statistical significance of these types. The feature is enabled by default as of v3.0.0, and remains available but disabled by default for prior versions.

The goal of this feature is to reduce the number of messages submitted to the Datadog Agent. Minimizing message volume allows us to reduce load on the dogstatsd server side and mitigate packet drops. The feature has been implemented such that impact on CPU and memory should be quite minimal on the client side. Users might be concerned with what could be perceived as a loss of resolution by resorting to aggregation on the client, this should not be the case. It's worth noting the dogstatsd server implemented in the Datadog Agent already aggregates messages over a certain flush period, therefore so long as the flush interval configured on the client side is smaller than said flush interval on the server side there should no loss in resolution.

Configuration

Enabling aggregation is simple, you just need to set the appropriate options with the client builder.

You can just enable aggregation by calling the enableAggregation(bool) method on the builder.

There are two clent-side aggregation knobs available:

  • aggregationShards(int): determines the number of shards in the aggregator, this feature is aimed at mitigating the effects of map locking in highly concurrent scenarios. Defaults to 4.
  • aggregationFlushInterval(int): sets the period of time in milliseconds in which the aggregator will flush its metrics into the sender. Defaults to 3000 milliseconds.
StatsDClient client = new NonBlockingStatsDClientBuilder()
    .hostname("localhost")
    .port(8125)
    .enableAggregation(true)
    .aggregationFlushInterval(3000)  // optional: in milliseconds
    .aggregationShards(8)  // optional: defaults to 4
    .build();

Usage

In order to use DogStatsD metrics, events, and Service Checks the Agent must be running and available.

Metrics

After the client is created, you can start sending custom metrics to Datadog. See the dedicated Metric Submission: DogStatsD documentation to see how to submit all supported metric types to Datadog with working code examples:

Some options are suppported when submitting metrics, like applying a Sample Rate to your metrics or tagging your metrics with your custom tags.

Events

After the client is created, you can start sending events to your Datadog Event Stream. See the dedicated Event Submission: DogStatsD documentation to see how to submit an event to your Datadog Event Stream.

Service Checks

After the client is created, you can start sending Service Checks to Datadog. See the dedicated Service Check Submission: DogStatsD documentation to see how to submit a Service Check to Datadog.

More Repositories

1

go-profiler-notes

felixge's notes on the various go profiling methods that are available.
Jupyter Notebook
3,255
star
2

glommio

Glommio is a thread-per-core crate that makes writing highly parallel asynchronous applications in a thread-per-core architecture easier for rustaceans.
Rust
2,871
star
3

datadog-agent

Main repository for Datadog Agent
Go
2,640
star
4

stratus-red-team

☁️ ⚡ Granular, Actionable Adversary Emulation for the Cloud
Go
1,600
star
5

dd-agent

Datadog Agent Version 5
Python
1,291
star
6

integrations-core

Core integrations of the Datadog Agent
Python
856
star
7

zstd

Zstd wrapper for Go
C
712
star
8

the-monitor

Markdown files for Datadog's longform blog posts: https://www.datadoghq.com/blog/
Python
608
star
9

dd-trace-js

JavaScript APM Tracer
JavaScript
601
star
10

datadogpy

The Datadog Python library
Python
575
star
11

dd-trace-go

Datadog Go Library including APM tracing, profiling, and security monitoring.
Go
545
star
12

dd-trace-java

Datadog APM client for Java
Java
500
star
13

dd-trace-py

Datadog Python APM Client
Python
498
star
14

yubikey

YubiKey at Datadog
Shell
493
star
15

kafka-kit

Kafka storage rebalancing, automated replication throttle, cluster API and more
Go
480
star
16

guarddog

🐍 🔍 GuardDog is a CLI tool to Identify malicious PyPI and npm packages
Python
478
star
17

dd-trace-php

Datadog PHP Clients
PHP
468
star
18

documentation

The source for Datadog's documentation site.
JavaScript
408
star
19

dd-trace-dotnet

.NET Client Library for Datadog APM
C#
403
star
20

security-labs-pocs

Proof of concept code for Datadog Security Labs referenced exploits.
Shell
355
star
21

go-python3

Go bindings to the CPython-3 API
Go
344
star
22

datadog-go

go dogstatsd client library for datadog
Go
332
star
23

terraform-provider-datadog

Terraform Datadog provider
Go
329
star
24

datadog-serverless-functions

Repo of AWS Lambda and Azure Functions functions that process streams and send data to Datadog
Python
326
star
25

helm-charts

Helm charts for Datadog products
Go
320
star
26

docker-dd-agent

Datadog Agent Dockerfile for Trusted Builds.
Roff
302
star
27

ansible-datadog

Ansible role for Datadog Agent
Jinja
288
star
28

datadog-operator

Datadog Agent Kubernetes Operator
Go
281
star
29

browser-sdk

Datadog Browser SDK
TypeScript
272
star
30

dd-trace-rb

Datadog Tracing Ruby Client
Ruby
261
star
31

threatest

Threatest is a CLI and Go framework for end-to-end testing threat detection rules.
Go
260
star
32

integrations-extras

Community developed integrations and plugins for the Datadog Agent.
Python
239
star
33

watermarkpodautoscaler

Custom controller that extends the Horizontal Pod Autoscaler
Go
206
star
34

pupernetes

Spin up a full fledged Kubernetes environment designed for local development & CI
Go
200
star
35

Miscellany

Miscellaneous scripts and tools
Python
197
star
36

php-datadogstatsd

A PHP client for DogStatsd
PHP
185
star
37

dd-sdk-ios

Datadog SDK for iOS - Swift and Objective-C.
Swift
172
star
38

dogstatsd-ruby

A Ruby client for DogStatsd
Ruby
166
star
39

sketches-go

Go implementations of the distributed quantile sketch algorithm DDSketch
Go
142
star
40

chaos-controller

🐒 🔥 Datadog Failure Injection System for Kubernetes
C
142
star
41

dd-sdk-android

Datadog SDK for Android (Compatible with Kotlin and Java)
Kotlin
137
star
42

kvexpress

Go program to move data in and out of Consul's KV store.
Go
128
star
43

HASH

HASH (HTTP Agnostic Software Honeypot)
JavaScript
119
star
44

docker-compose-example

A working example of using Docker Compose with Datadog
Python
116
star
45

trace-examples

trace sample apps
Python
113
star
46

sketches-java

DDSketch: A Fast and Fully-Mergeable Quantile Sketch with Relative-Error Guarantees.
Java
108
star
47

ebpf-manager

This manager helps handle the life cycle of your eBPF programs
Go
106
star
48

dd-sdk-reactnative

Datadog SDK for ReactNative
TypeScript
105
star
49

gohai

System information collector
Go
102
star
50

datadog-lambda-js

The Datadog AWS Lambda Library for Node
TypeScript
101
star
51

chef-datadog

Chef cookbook for Datadog Agent & Integrations
Ruby
97
star
52

piecewise

Functions for piecewise regression on time series data
Python
96
star
53

malicious-software-packages-dataset

An open-source dataset of malicious software packages found in the wild, 100% vetted by humans.
Python
96
star
54

extendeddaemonset

Kubernetes Extended Daemonset controller
Go
95
star
55

datadog-api-client-go

Golang client for the Datadog API
Go
95
star
56

jmxfetch

Export JMX metrics
Java
95
star
57

dogstatsd-csharp-client

A DogStatsD client for C#/.NET
C#
94
star
58

gostackparse

Package gostackparse parses goroutines stack traces as produced by panic() or debug.Stack() at ~300 MiB/s.
Go
94
star
59

ansible-datadog-callback

Ansible callback to get stats & events directly into Datadog http://datadoghq.com
Python
93
star
60

dogapi-rb

Ruby client for Datadog's API
Ruby
92
star
61

redux-doghouse

Scoping helpers for building reusable components with Redux
JavaScript
90
star
62

build-plugin

Track your build performances like never before.
TypeScript
89
star
63

serverless-plugin-datadog

Serverless plugin to automagically instrument your Lambda functions with Datadog
TypeScript
87
star
64

ecommerce-workshop

Example eCommerce App for workshops and observability
Ruby
86
star
65

datadog-ci

Use Datadog from your CI.
TypeScript
85
star
66

ebpfbench

profile eBPF programs from Go
Go
83
star
67

datadog-lambda-python

The Datadog AWS Lambda Layer for Python
Python
80
star
68

sketches-py

Python implementations of the distributed quantile sketch algorithm DDSketch
Python
77
star
69

dirtypipe-container-breakout-poc

Container Excape PoC for CVE-2022-0847 "DirtyPipe"
77
star
70

ddqa

Datadog's QA manager for releases of GitHub repositories
Python
72
star
71

datadog-trace-agent

Datadog Trace Agent archive (pre-6.10.0)
70
star
72

datadog-api-client-typescript

Typescript client for the Datadog API
TypeScript
69
star
73

heroku-buildpack-datadog

Heroku Buildpack to run the Datadog Agent in a Dyno
Shell
69
star
74

datadog-api-client-python

Python client for the Datadog API
Python
68
star
75

datadog-static-analyzer

Datadog Static Analyzer
Rust
64
star
76

orchestrion

A tool for adding instrumentation to Go code
Go
61
star
77

managed-kubernetes-auditing-toolkit

All-in-one auditing toolkit for identifying common security issues in managed Kubernetes environments. Currently supports AWS EKS.
Go
60
star
78

lading

A suite of data generation and load testing tools
Rust
60
star
79

datadog-lambda-extension

Rust
60
star
80

jsonapi

A marshaler/unmarshaler for JSON:API.
Go
59
star
81

datadog-cdk-constructs

CDK construct library to automagically instrument your Lambda functions with Datadog
TypeScript
58
star
82

datadog-lambda-go

The Datadog AWS Lambda package for Go
Go
57
star
83

serilog-sinks-datadog-logs

Serilog Sink that sends log events to Datadog https://www.datadoghq.com/
C#
53
star
84

puppet-datadog-agent

Puppet module to install the Datadog agent
Ruby
50
star
85

datadog-api-client-java

Java client for the Datadog API
Java
48
star
86

opencensus-go-exporter-datadog

Datadog exporter for OpenCensus metrics
Go
47
star
87

gello

:octocat: A self-hosted server for managing Trello cards based on GitHub webhook events
Python
45
star
88

datadog-cloudformation-resources

Python
44
star
89

ebpf-training

Go
44
star
90

jenkins-datadog-plugin

ARCHIVED: Current repository is now located https://github.com/jenkinsci/datadog-plugin
Java
42
star
91

effective-dashboards

A curated list of useful Datadog dashboards and Dashboard design best practices
40
star
92

dd-sdk-flutter

Flutter bindings and tools for utilizing Datadog Mobile SDKs
Dart
40
star
93

dd-opentracing-cpp

Datadog Opentracing C++ Client
C++
40
star
94

synthetics-ci-github-action

Use Browser and API tests in your CI/CD with Datadog Continuous Testing
TypeScript
40
star
95

rum-react-integration-examples

rum-react-integration
TypeScript
39
star
96

fluent-plugin-datadog

Fluentd output plugin for Datadog: https://www.datadog.com
Ruby
38
star
97

import-in-the-middle

Like `require-in-the-middle`, but for ESM import
JavaScript
38
star
98

ddprof

The Datadog Native Profiler for Linux
C++
35
star
99

apigentools

Generate API clients with ease
Python
32
star
100

brod

An unmaintained python client to Kafka 0.6
Python
31
star