A Ruby client for DogStatsd
Clone or download
#43 Compare This branch is 228 commits ahead, 7 commits behind jeremy:master.
Latest commit 570f3c0 Aug 20, 2018
Failed to load latest commit information.
examples fix rubocop errors Feb 3, 2018
lib/datadog release 4.4.0 Aug 20, 2018
spec add .open for short-lived reporting that does not leave sockets around Jun 28, 2018
.gitignore Remove tracking of Gemfile.lock Jul 10, 2013
.rubocop.yml fail fast on unknown options Jun 6, 2018
.travis.yml fail fast on unknown options Jun 6, 2018
CHANGELOG.md newline Aug 20, 2018
Gemfile fail fast on unknown options Jun 6, 2018
LICENSE.txt Initial commit to statsd. Feb 18, 2011
README.md add .open for short-lived reporting that does not leave sockets around Jun 28, 2018
Rakefile make rake run rubocop too for fast local testing Jun 6, 2018
dogstatsd-ruby.gemspec fail fast on unknown options Jun 6, 2018



A client for DogStatsD, an extension of the StatsD metric server for Datadog.

Build Status

Quick Start Guide

First install the library:

gem install dogstatsd-ruby

Then start instrumenting your code:

# Load the dogstats module.
require 'datadog/statsd'

# Create a stats instance.
statsd = Datadog::Statsd.new('localhost', 8125)

# you could also create a statsd class if you need a drop in replacement
# class Statsd < Datadog::Statsd
# end

# Increment a counter.

# Record a gauge 50% of the time.
statsd.gauge('users.online', 123, :sample_rate=>0.5)

# Sample a histogram
statsd.histogram('file.upload.size', 1234)

# Time a block of code
statsd.time('page.render') do

# Send several metrics at the same time
# All metrics will be buffered and sent in one packet when the block completes
statsd.batch do |s|
  s.gauge('users.online', 123)

# Tag a metric.
statsd.histogram('query.time', 10, :tags => ["version:1"])

# Auto-close socket after end of block
Datadog::Statsd.open('localhost', 8125) do |s|

You can also post events to your stream. You can tag them, set priority and even aggregate them with other events.

Aggregation in the stream is made on hostname/event_type/source_type/aggregation_key.

# Post a simple message
statsd.event("There might be a storm tomorrow", "A friend warned me earlier.")

# Cry for help
statsd.event("SO MUCH SNOW", "Started yesterday and it won't stop !!", :alert_type => "error", :tags => ["urgent", "endoftheworld"])


Full API documentation is available here.


To suggest a feature, report a bug, or general discussion, head over here.

Change Log


dogstatsd-ruby is forked from Rien Henrichs original Statsd client.

Copyright (c) 2011 Rein Henrichs. See LICENSE.txt for further details.