A client for DogStatsD, an extension of the StatsD metric server for Datadog. Full API documentation is available in DogStatsD-ruby rubydoc.
First install the library:
gem install dogstatsd-ruby
To instantiate a DogStatsd client:
# Import the library require 'datadog/statsd' # Create a DogStatsD client instance. statsd = Datadog::Statsd.new('localhost', 8125)
Or if you want to connect over Unix Domain Socket:
# Connection over Unix Domain Socket statsd = Datadog::Statsd.new(socket_path: '/path/to/socket/file')
Origin detection over UDP
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.
To enable origin detection over UDP, add the following lines to your application manifest
env: - name: DD_ENTITY_ID valueFrom: fieldRef: fieldPath: metadata.uid
The DogStatsD client attaches an internal tag,
entity_id. The value of this tag is the content of the
DD_ENTITY_ID environment variable, which is the pod’s UID.
In order to use DogStatsD metrics, events, and Service Checks the Agent must be running and available.
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:
- Submit a COUNT metric.
- Submit a GAUGE metric.
- Submit a SET metric
- Submit a HISTOGRAM metric
- Submit a DISTRIBUTION metric
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 DogStatsD-ruby rubydoc.
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 Datadog your Event Stream.
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.
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 for both UDS (8192 bytes)
and UDP (1432 bytes) in order 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 parameter
# Create a DogStatsD client instance. statsd = Datadog::Statsd.new('localhost', 8125, buffer_max_payload_size: 4096)
dogstatsd-ruby is forked from Rein Henrichs original Statsd client.
Copyright (c) 2011 Rein Henrichs. See LICENSE.txt for further details.