Class: StatsdServer::Output::Tcp

Inherits:
Object
  • Object
show all
Defined in:
lib/statsdserver/output/tcp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Tcp

Returns a new instance of Tcp.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/statsdserver/output/tcp.rb', line 9

def initialize(opts = {})
  if opts["host"].nil?
    raise ArgumentError, "missing host in [output:tcp] config section"
  end

  if opts["port"].nil?
    raise ArgumentError, "missing port in [output:tcp] config section"
  end

  @opts = opts
  @logger = Logger.new(STDOUT)
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/statsdserver/output/tcp.rb', line 6

def logger
  @logger
end

Instance Method Details

#send(str) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/statsdserver/output/tcp.rb', line 23

def send(str)
  @socket ||= connect
  begin
    @socket.write("#{str}")
  rescue => e
    # set @socket to nil to force a re-connect, then pass up the exception
    @socket.close rescue nil
    @socket = nil
    raise
  end
end