Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support for the "set" stat type. #29

Merged
merged 1 commit into from

3 participants

@petemounce

From the etsy/statsd/README.md,

StatsD supports counting unique occurences of events between 
flushes, using a Set to store all occuring events.

This change adds support for sending metrics of the set type to a statsd server.

Note: I'm not convinced I've fully understand the intent of the event-type (see the rdoc I wrote), but I'm pretty sure the code is doing the correct thing.

@petemounce petemounce Add support for the "set" stat type.
From the README.md, "StatsD supports counting unique occurences of
events between flushes, using a Set to store all occuring events."

This change adds support for sending metrics of that type to a
statsd server.
dd6594c
@reinh
Owner

:+1: Thanks for the PR! Tossing over to @raggi.

@raggi
Collaborator

LGTM, thanks!

@raggi raggi merged commit b9893d1 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 10, 2012
  1. @petemounce

    Add support for the "set" stat type.

    petemounce authored
    From the README.md, "StatsD supports counting unique occurences of
    events between flushes, using a Set to store all occuring events."
    
    This change adds support for sending metrics of that type to a
    statsd server.
This page is out of date. Refresh to see the latest.
Showing with 31 additions and 0 deletions.
  1. +16 −0 lib/statsd.rb
  2. +15 −0 spec/statsd_spec.rb
View
16 lib/statsd.rb
@@ -181,6 +181,22 @@ def gauge(stat, value, sample_rate=1)
send_stats stat, value, :g, sample_rate
end
+ # Sends an arbitary set value for the given stat to the statsd server.
+ #
+ # This is for recording counts of unique events, which are useful to
+ # see on graphs to correlate to other values. For example, a deployment
+ # might get recorded as a set, and be drawn as annotations on a CPU history
+ # graph.
+ #
+ # @param [String] stat stat name.
+ # @param [Numeric] value event value.
+ # @param [Numeric] sample_rate sample rate, 1 for always
+ # @example Report a deployment happening:
+ # $statsd.set('deployment', DEPLOYMENT_EVENT_CODE)
+ def set(stat, value, sample_rate=1)
+ send_stats stat, value, :s, sample_rate
+ end
+
# Sends a timing (in ms) for the given stat to the statsd server. The
# sample_rate determines what percentage of the time this report is sent. The
# statsd server then uses the sample_rate to correctly track the average
View
15 spec/statsd_spec.rb
@@ -111,6 +111,21 @@ class Statsd
end
end
+ describe "#set" do
+ it "should format the message according to the statsd spec" do
+ @statsd.set('foobar', 765)
+ @socket.recv.must_equal ['foobar:765|s']
+ end
+
+ describe "with a sample rate" do
+ before { class << @statsd; def rand; 0; end; end } # ensure delivery
+ it "should format the message according to the statsd spec" do
+ @statsd.set('foobar', 500, 0.5)
+ @socket.recv.must_equal ['foobar:500|s|@0.5']
+ end
+ end
+ end
+
describe "#time" do
it "should format the message according to the statsd spec" do
@statsd.time('foobar') { 'test' }
Something went wrong with that request. Please try again.