class Woody::Statsd::Client
Public Class Methods
get(namespace = ENV['STATSD_NS'], host = ENV['STATSD_HOST'], port = ENV['STATSD_PORT'])
click to toggle source
# File lib/woody/statsd/client.rb, line 7 def get(namespace = ENV['STATSD_NS'], host = ENV['STATSD_HOST'], port = ENV['STATSD_PORT']) @client ||= new(namespace, host, port) end
new(namespace, host, port)
click to toggle source
# File lib/woody/statsd/client.rb, line 12 def initialize(namespace, host, port) @host = host || "localhost" @port = port || 8188 @socket = UDPSocket.new @ns = namespace || "nanit" end
Public Instance Methods
counter_stat(stat, inc)
click to toggle source
# File lib/woody/statsd/client.rb, line 35 def counter_stat(stat, inc) "#{@ns}.#{stat}:#{inc}|c\n" end
increment(stat, inc = 1)
click to toggle source
# File lib/woody/statsd/client.rb, line 19 def increment(stat, inc = 1) send_to_socket counter_stat(stat, inc) end
send_to_socket(msg)
click to toggle source
# File lib/woody/statsd/client.rb, line 43 def send_to_socket(msg) begin @socket.send msg, 0, @host, @port nil rescue => e puts "WOODY_ERROR #{e.inspect} HOST #{@host} PORT #{@port}" end end
timing(stat, time_took)
click to toggle source
# File lib/woody/statsd/client.rb, line 23 def timing(stat, time_took) send_to_socket timing_stat(stat, time_took) end
timing_stat(stat, time_took)
click to toggle source
# File lib/woody/statsd/client.rb, line 39 def timing_stat(stat, time_took) "#{@ns}.#{stat}:#{time_took.round}|ms\n" end
with_timing(stat) { || ... }
click to toggle source
# File lib/woody/statsd/client.rb, line 27 def with_timing(stat) start = Time.now.to_f res = yield time_took = (Time.now.to_f - start) * 1000 timing(stat, time_took) res end