class GraphiteClient
Public Class Methods
new(host)
click to toggle source
“host” or “host:port”
# File lib/graphite_client.rb, line 5 def initialize(host) @host, @port = host.split ':' @port = 2003 if ! @port @port = @port.to_i end
Public Instance Methods
close_socket()
click to toggle source
# File lib/graphite_client.rb, line 25 def close_socket @socket.close if @socket @socket = nil end
report(key, value, time = Time.now)
click to toggle source
# File lib/graphite_client.rb, line 16 def report(key, value, time = Time.now) begin socket.write("#{key} #{value.to_f} #{time.to_i}\n") rescue Errno::EPIPE, Errno::EHOSTUNREACH, Errno::ECONNREFUSED @socket = nil nil end end
socket()
click to toggle source
# File lib/graphite_client.rb, line 11 def socket return @socket if @socket && !@socket.closed? @socket = TCPSocket.new(@host, @port) end