Class: StatsdServer::Output::Tcp
- Inherits:
-
Object
- Object
- StatsdServer::Output::Tcp
- Defined in:
- lib/statsdserver/output/tcp.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Tcp
constructor
A new instance of Tcp.
- #send(str) ⇒ Object
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
#logger ⇒ Object
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 |