Class: GraphiteClient

Inherits:
Object
  • Object
show all
Defined in:
lib/graphite_client.rb,
lib/graphite_client/event_reporter.rb

Defined Under Namespace

Classes: EventReporter

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ GraphiteClient

“host” or “host:port”



5
6
7
8
9
# File 'lib/graphite_client.rb', line 5

def initialize(host)
  @host, @port = host.split ':'
  @port = 2003 if ! @port
  @port = @port.to_i
end

Instance Method Details

#close_socketObject



25
26
27
28
# File 'lib/graphite_client.rb', line 25

def close_socket
  @socket.close if @socket
  @socket = nil
end

#report(key, value, time = Time.now) ⇒ Object



16
17
18
19
20
21
22
23
# 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

#socketObject



11
12
13
14
# File 'lib/graphite_client.rb', line 11

def socket
  return @socket if @socket && !@socket.closed?
  @socket = TCPSocket.new(@host, @port)
end