lib/statsd.rb in statsd-client-0.0.4 vs lib/statsd.rb in statsd-client-0.0.5
- old
+ new
@@ -1,11 +1,11 @@
require 'socket'
require 'resolv'
class Statsd
- Version = '0.0.4'
+ Version = '0.0.5'
class << self
attr_accessor :host, :port
@@ -18,12 +18,17 @@
@host = h
end
# +stat+ to log timing for
# +time+ is the time to log in ms
- def timing(stat, time, sample_rate = 1)
- send_stats "#{stat}:#{time}|ms", sample_rate
+ def timing(stat, time = nil, sample_rate = 1)
+ if block_given?
+ start_time = Time.now.to_f
+ yield
+ time = ((Time.now.to_f - start_time) * 1000).floor
+ end
+ send_stats("#{stat}:#{time}|ms", sample_rate)
end
# +stats+ can be a string or an array of strings
def increment(stats, sample_rate = 1)
update_counter stats, 1, sample_rate
@@ -72,6 +77,6 @@
true
end
end
-end
\ No newline at end of file
+end