Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/github/statsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions spec/statsd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down