diff --git a/lib/github/statsd.rb b/lib/github/statsd.rb index 56730e8..fe7430b 100644 --- a/lib/github/statsd.rb +++ b/lib/github/statsd.rb @@ -91,6 +91,7 @@ def namespace=(namespace) TIMING_TYPE = "ms".freeze GAUGE_TYPE = "g".freeze HISTOGRAM_TYPE = "h".freeze + DISTRIBUTION_TYPE = "d".freeze def initialize(client_class = nil) @shards = [] @@ -187,6 +188,11 @@ def time(stat, sample_rate=1) # statsd server then uses the sample_rate to correctly track the average # for the stat. def histogram(stat, value, sample_rate=1); send stat, value, HISTOGRAM_TYPE, sample_rate end + + # A modified gauge that submits a distribution of values over a sample period. + # Arithmetic and statistical calculations (percetiles, average, etc.) on the data set + # are peformed server side rather than client side like a histogram. + def distribution(stat, value, sample_rate=1); send stat, value, DISTRIBUTION_TYPE, sample_rate end private def sampled(sample_rate) diff --git a/spec/statsd_spec.rb b/spec/statsd_spec.rb index 14d0b21..30bbc9e 100644 --- a/spec/statsd_spec.rb +++ b/spec/statsd_spec.rb @@ -68,6 +68,13 @@ class << @statsd end end + describe "#distribution" do + it "should format the message according to the statsd spec" do + @statsd.distribution('foobar', 500) + @statsd.shards.first.recv.must_equal ["foobar:500|d"] + end + end + describe "#time" do it "should format the message according to the statsd spec" do @statsd.time('foobar') { sleep(0.001); 'test' }