Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
do less work if not sampled
Browse files Browse the repository at this point in the history
  • Loading branch information
gburt committed Dec 30, 2011
1 parent f18a9c3 commit 1133309
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/statsd.rb
Expand Up @@ -94,9 +94,11 @@ def sampled(sample_rate)
end end


def send(stat, delta, type, sample_rate=1) def send(stat, delta, type, sample_rate=1)
prefix = "#{@namespace}." unless @namespace.nil? sampled(sample_rate) do
stat = stat.to_s.gsub('::', '.').gsub(RESERVED_CHARS_REGEX, '_') prefix = "#{@namespace}." unless @namespace.nil?
sampled(sample_rate) { send_to_socket("#{prefix}#{stat}:#{delta}|#{type}#{'|@' << sample_rate.to_s if sample_rate < 1}") } stat = stat.to_s.gsub('::', '.').gsub(RESERVED_CHARS_REGEX, '_')
send_to_socket("#{prefix}#{stat}:#{delta}|#{type}#{'|@' << sample_rate.to_s if sample_rate < 1}")
end
end end


def send_to_socket(message) def send_to_socket(message)
Expand Down

0 comments on commit 1133309

Please sign in to comment.