class Graphite

Public Class Methods

new(token, host, port = 2003) click to toggle source
# File lib/graphite.rb, line 4
def initialize(token, host, port = 2003)
  @token, @host, @port = token, host, port
end

Public Instance Methods

measure(stat, value = nil) { || ... } click to toggle source
# File lib/graphite.rb, line 8
def measure(stat, value = nil)
  if block_given?
    start = Time.now
    yield
    value = ((Time.now - start) * 1000).round
  end

  send_to_socket("#{stat} #{value}") unless value.nil?
end

Private Instance Methods

send_to_socket(message) click to toggle source
# File lib/graphite.rb, line 20
def send_to_socket(message)
  return if defined?(Rails) && !Rails.env.production?

  socket.send("#{@token}.#{message}", 0, @host, @port) rescue nil
end
socket() click to toggle source
# File lib/graphite.rb, line 26
def socket
  @socket ||= UDPSocket.new
end