• Stars
    star
    332
  • Rank 126,957 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

go dogstatsd client library for datadog

Build Status

Datadog Go

Godoc license

datadog-go is a library that provides a DogStatsD client in Golang.

Go 1.12+ is officially supported. Older versions might work but are not tested.

The following documentation is available:

New major version

The new major version v5 is now the default. All new features will be added to this version and only bugfixes will be backported to v4 (see v4 branch).

v5 introduce a number of breaking changes compare to v4, see the CHANGELOG for more information.

Note that the import paths for v5 and v4 are different:

  • v5: github.com/DataDog/datadog-go/v5/statsd
  • v4: github.com/DataDog/datadog-go/statsd

When migrating to the v5 you will need to upgrade your imports.

Installation

Get the code with:

$ go get github.com/DataDog/datadog-go/v5/statsd

Then create a new DogStatsD client:

package main

import (
    "log"
    "github.com/DataDog/datadog-go/v5/statsd"
)

func main() {
    statsd, err := statsd.New("127.0.0.1:8125")
    if err != nil {
        log.Fatal(err)
    }
}

Find a list of all the available options for your DogStatsD Client in the Datadog-go godoc documentation or in Datadog public DogStatsD documentation.

Supported environment variables

  • If the addr parameter is empty, the client will:
    • First use the DD_DOGSTATSD_URL environment variables to build a target address. This must be a URL that start with either udp:// (to connect using UDP) or with unix:// (to use a Unix Domain Socket). Example for UDP url: DD_DOGSTATSD_URL=udp://localhost:8125 Example for UDS: DD_DOGSTATSD_URL=unix:///var/run/datadog/dsd.socket Example for Windows named pipeDD_AGENT_HOST=\\.\pipe\my_windows_pipe
    • Fallback to the DD_AGENT_HOST environment variables to build a target address. Example: DD_AGENT_HOST=127.0.0.1:8125 for UDP, DD_AGENT_HOST=unix:///path/to/socket for UDS and DD_AGENT_HOST=\\.\pipe\my_windows_pipe for Windows named pipe.
      • If DD_AGENT_HOST has no port it will default the port to 8125
      • You can use DD_AGENT_PORT to set the port if DD_AGENT_HOST does not have a port set for UDP Example: DD_AGENT_HOST=127.0.0.1 and DD_AGENT_PORT=1234 will create a UDP connection to 127.0.0.1:1234.
  • If the DD_ENTITY_ID environment variable is found, its value is injected as a global dd.internal.entity_id tag. The Datadog Agent uses this tag to insert container tags into the metrics.

To enable origin detection and set the DD_ENTITY_ID environment variable, add the following lines to your application manifest:

env:
  - name: DD_ENTITY_ID
    valueFrom:
      fieldRef:
        fieldPath: metadata.uid
  • DD_ENV, DD_SERVICE, and DD_VERSION can be used by the statsd client to set {env, service, version} as global tags for all data emitted.

Unix Domain Sockets Client

Agent v6+ accepts packets through a Unix Socket datagram connection. Details about the advantages of using UDS over UDP are available in the DogStatsD Unix Socket documentation. You can use this protocol by giving a unix:///path/to/dsd.socket address argument to the New constructor.

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:

Metric names must only contain ASCII alphanumerics, underscores, and periods. The client will not replace nor check for invalid characters.

Some options are suppported when submitting metrics, like applying a sample rate to your metrics or tagging your metrics with your custom tags. Find all the available functions to report metrics in the Datadog Go client GoDoc documentation.

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.

Client side aggregation

Starting with version 5.0.0 (and 3.6.0 in beta), the client offers aggregation or value packing on the client side.

This feature aims at reducing both the number of packets sent to the Agent and the packet drops in very high throughput scenarios.

The aggregation window is 2s by default and can be changed through WithAggregationInterval() option. Note that the aggregation window on the Agent side is 10s for DogStatsD metrics. So for example, setting an aggregation window of 3s in the client will produce a spike in your dashboard every 30 second for counts metrics (as the third 10s bucket on the Agent will receive 4 samples from the client).

Aggregation can be disabled using the WithoutClientSideAggregation() option.

The telemetry datadog.dogstatsd.client.metrics is unchanged and represents the number of metrics before aggregation. New metrics datadog.dogstatsd.client.aggregated_context and datadog.dogstatsd.client.aggregated_context_by_type have been introduced. See the Monitoring this client section.

"Basic" aggregation

Enabled by default, the client will aggregate gauge, count and set.

This can be disabled with the WithoutClientSideAggregation() option.

"Extended" aggregation

This feature is only compatible with Agent's version >=6.25.0 && <7.0.0 or Agent's versions >=7.25.0.

Disabled by default, the client can also pack multiple values for histogram, distribution and timing in one message. Real aggregation is not possible for those types since the Agent also aggregates and two aggregation levels would change the final value sent to Datadog.

When this option is enabled, the agent will buffer the metrics by combination of metric name and tags, and send them in the fewest number of messages.

For example, if we sample 3 times the same metric. Instead of sending on the network:

my_distribution_metric:21|d|#all,my,tags
my_distribution_metric:43.2|d|#all,my,tags
my_distribution_metric:1657|d|#all,my,tags

The client will send only one message:

my_distribution_metric:21:43.2:1657|d|#all,my,tags

This will greatly reduce network usage and packet drops but will slightly increase the memory and CPU usage of the client. Looking at the telemetry metrics datadog.dogstatsd.client.metrics_by_type / datadog.dogstatsd.client.aggregated_context_by_type will show the aggregation ratio for each type. This is an interesting data to know how useful extended aggregation is to your app.

This can be enabled with the WithExtendedClientSideAggregation() option.

Performance / Metric drops

Monitoring this client

This client automatically injects telemetry about itself in the DogStatsD stream. Those metrics will not be counted as custom and will not be billed. This feature can be disabled using the WithoutTelemetry option.

See Telemetry documentation to learn more about it.

Tweaking kernel options

In very high throughput environments it is possible to improve performance by changing the values of some kernel options.

Unix Domain Sockets

  • sysctl -w net.unix.max_dgram_qlen=X - Set datagram queue size to X (default value is usually 10).
  • sysctl -w net.core.wmem_max=X - Set the max size of the send buffer for all the host sockets.

Maximum packets size in high-throughput scenarios

In order to have the most efficient use of this library in high-throughput scenarios, default values for the maximum packets size have already been set to have the best usage of the underlying network. However, if you perfectly know your network and you know that a different value for the maximum packets size should be used, you can set it with the option WithMaxBytesPerPayload. Example:

package main

import (
    "log"
    "github.com/DataDog/datadog-go/v5/statsd"
)

func main() {
    statsd, err := statsd.New("127.0.0.1:8125", WithMaxBytesPerPayload(4096))
    if err != nil {
        log.Fatal(err)
    }
}

Development

Run the tests with:

$ go test

License

datadog-go is released under the MIT license.

Credits

Original code by ooyala.

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
3,076
star
3

datadog-agent

Main repository for Datadog Agent
Go
2,859
star
4

stratus-red-team

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

dd-agent

Datadog Agent Version 5
Python
1,291
star
6

integrations-core

Core integrations of the Datadog Agent
Python
917
star
7

KubeHound

Tool for building Kubernetes attack paths
Go
737
star
8

zstd

Zstd wrapper for Go
C
732
star
9

dd-trace-go

Datadog Go Library including APM tracing, profiling, and security monitoring.
Go
659
star
10

dd-trace-js

JavaScript APM Tracer
JavaScript
636
star
11

the-monitor

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

guarddog

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

datadogpy

The Datadog Python library
Python
575
star
14

dd-trace-py

Datadog Python APM Client
Python
519
star
15

dd-trace-java

Datadog APM client for Java
Java
500
star
16

yubikey

YubiKey at Datadog
Shell
494
star
17

dd-trace-php

Datadog PHP Clients
PHP
491
star
18

kafka-kit

Kafka storage rebalancing, automated replication throttle, cluster API and more
Go
485
star
19

documentation

The source for Datadog's documentation site.
HTML
471
star
20

dd-trace-dotnet

.NET Client Library for Datadog APM
C#
443
star
21

security-labs-pocs

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

go-python3

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

helm-charts

Helm charts for Datadog products
Go
344
star
24

terraform-provider-datadog

Terraform Datadog provider
Go
329
star
25

datadog-serverless-functions

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

docker-dd-agent

Datadog Agent Dockerfile for Trusted Builds.
Roff
302
star
27

browser-sdk

Datadog Browser SDK
TypeScript
302
star
28

datadog-operator

Kubernetes Operator for Datadog Resources
Go
301
star
29

ansible-datadog

Ansible role for Datadog Agent
Jinja
299
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
252
star
33

watermarkpodautoscaler

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

pupernetes

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

Miscellany

Miscellaneous scripts and tools
Python
197
star
36

dd-sdk-ios

Datadog SDK for iOS - Swift and Objective-C.
Swift
195
star
37

php-datadogstatsd

A PHP client for DogStatsd
PHP
185
star
38

java-dogstatsd-client

Java statsd client library
Java
175
star
39

sketches-go

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

dogstatsd-ruby

A Ruby client for DogStatsd
Ruby
166
star
41

dd-sdk-android

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

chaos-controller

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

kvexpress

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

HASH

HASH (HTTP Agnostic Software Honeypot)
JavaScript
128
star
45

malicious-software-packages-dataset

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

ebpf-manager

This manager helps handle the life cycle of your eBPF programs
Go
118
star
47

docker-compose-example

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

orchestrion

Automatic compile-time instrumentation of Go code
Go
115
star
49

dd-sdk-reactnative

Datadog SDK for ReactNative
TypeScript
115
star
50

trace-examples

trace sample apps
Python
113
star
51

sketches-java

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

datadog-lambda-js

The Datadog AWS Lambda Library for Node
TypeScript
105
star
53

gohai

System information collector
Go
102
star
54

build-plugins

A set of universal bundler plugins to interact with Datadog directly from your builds.
TypeScript
101
star
55

jmxfetch

Export JMX metrics
Java
98
star
56

chef-datadog

Chef cookbook for Datadog Agent & Integrations
Ruby
97
star
57

piecewise

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

extendeddaemonset

Kubernetes Extended Daemonset controller
Go
96
star
59

datadog-static-analyzer

Datadog Static Analyzer
Rust
96
star
60

datadog-api-client-go

Golang client for the Datadog API
Go
95
star
61

ansible-datadog-callback

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

dogstatsd-csharp-client

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

gostackparse

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

dogapi-rb

Ruby client for Datadog's API
Ruby
92
star
65

redux-doghouse

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

ecommerce-workshop

Example eCommerce App for workshops and observability
Ruby
89
star
67

serverless-plugin-datadog

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

ebpfbench

## Auto-archived due to inactivity. ## profile eBPF programs from Go
Go
87
star
69

datadog-ci

Use Datadog from your CI.
TypeScript
85
star
70

sketches-py

Python implementations of the distributed quantile sketch algorithm DDSketch
Python
83
star
71

datadog-lambda-python

The Datadog AWS Lambda Layer for Python
Python
83
star
72

ddqa

Datadog's QA manager for releases of GitHub repositories
Python
82
star
73

datadog-api-client-typescript

Typescript client for the Datadog API
TypeScript
77
star
74

dirtypipe-container-breakout-poc

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

datadog-trace-agent

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

heroku-buildpack-datadog

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

datadog-lambda-extension

Rust
68
star
78

datadog-api-client-python

Python client for the Datadog API
Python
68
star
79

datadog-cdk-constructs

CDK construct library to automagically instrument your Lambda functions with Datadog
TypeScript
65
star
80

lading

A suite of data generation and load testing tools
Rust
64
star
81

jsonapi

A marshaler/unmarshaler for JSON:API.
Go
62
star
82

datadog-api-client-java

Java client for the Datadog API
Java
61
star
83

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
84

datadog-lambda-go

The Datadog AWS Lambda package for Go
Go
59
star
85

serilog-sinks-datadog-logs

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

puppet-datadog-agent

Puppet module to install the Datadog agent
Ruby
50
star
87

effective-dashboards

A curated list of useful Datadog dashboards and Dashboard design best practices
47
star
88

opencensus-go-exporter-datadog

Datadog exporter for OpenCensus metrics
Go
47
star
89

gello

## Auto-archived due to inactivity. ## :octocat: A self-hosted server for managing Trello cards based on GitHub webhook events
Python
45
star
90

datadog-cloudformation-resources

Python
44
star
91

ebpf-training

Go
44
star
92

dd-sdk-flutter

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

jenkins-datadog-plugin

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

synthetics-ci-github-action

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

dd-opentracing-cpp

Datadog Opentracing C++ Client
C++
40
star
96

rum-react-integration-examples

rum-react-integration
TypeScript
39
star
97

fluent-plugin-datadog

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

datadog-sync-cli

Datadog cli tool to sync resources across organizations.
Python
38
star
99

ddprof

The Datadog Native Profiler for Linux
C++
36
star
100

cloudformation-template

Easily set up the Datadog AWS integration using CloudFormation
Shell
34
star