Skip to content

Instantly share code, notes, and snippets.

@ColinDKelley
Created September 11, 2012 22:06
Show Gist options
  • Save ColinDKelley/3702480 to your computer and use it in GitHub Desktop.
Save ColinDKelley/3702480 to your computer and use it in GitHub Desktop.
rr_monitoring
module RRMonitoring
class Statistic
STATS_HOST = "stats.ringrevenue.net"
STATS_PORT = 8125
def timing(name, &blk)
start = Time.now
yield
finish = Time.now
elapsed = ((finish - start) * 1000.0).to_i
send_stat("#{name}:#{elapsed}|ms")
end
def count(name, number)
send_stat("#{name}:#{number}|c")
end
def gauge(name, value)
send_stat("#{name}:#{value}|g")
end
def socket
@socket ||= UDPSocket.new
end
def send_stat(descriptor)
socket.send(descriptor, 0, STATS_HOST, STATS_PORT)
end
end
end
@@statistic = RRMonitoring::Statistic.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment