Class: Datadog::Statsd::Connection
- Inherits:
-
Object
- Object
- Datadog::Statsd::Connection
- Defined in:
- lib/datadog/statsd.rb
Constant Summary collapse
- DEFAULT_HOST =
'127.0.0.1'
- DEFAULT_PORT =
8125
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
StatsD host.
-
#port ⇒ Object
readonly
StatsD port.
-
#socket_path ⇒ Object
readonly
DogStatsd unix socket path.
Instance Method Summary collapse
-
#close ⇒ Object
Close the underlying socket.
-
#initialize(host, port, socket_path, logger) ⇒ Connection
constructor
A new instance of Connection.
- #write(message) ⇒ Object
Constructor Details
#initialize(host, port, socket_path, logger) ⇒ Connection
Returns a new instance of Connection.
36 37 38 39 40 41 |
# File 'lib/datadog/statsd.rb', line 36 def initialize(host, port, socket_path, logger) @host = host || DEFAULT_HOST @port = port || DEFAULT_PORT @socket_path = socket_path @logger = logger end |
Instance Attribute Details
#host ⇒ Object (readonly)
StatsD host. Defaults to 127.0.0.1.
28 29 30 |
# File 'lib/datadog/statsd.rb', line 28 def host @host end |
#port ⇒ Object (readonly)
StatsD port. Defaults to 8125.
31 32 33 |
# File 'lib/datadog/statsd.rb', line 31 def port @port end |
#socket_path ⇒ Object (readonly)
DogStatsd unix socket path. Not used by default.
34 35 36 |
# File 'lib/datadog/statsd.rb', line 34 def socket_path @socket_path end |
Instance Method Details
#close ⇒ Object
Close the underlying socket
80 81 82 |
# File 'lib/datadog/statsd.rb', line 80 def close @socket && @socket.close end |
#write(message) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/datadog/statsd.rb', line 43 def write() @logger.debug { "Statsd: #{}" } if @logger if @socket_path.nil? socket.send(, 0) else socket.sendmsg_nonblock() end rescue StandardError => boom # Give up on this socket if it looks like it is bad bad_socket = !@socket_path.nil? && ( boom.is_a?(Errno::ECONNREFUSED) || boom.is_a?(Errno::ECONNRESET) || boom.is_a?(Errno::ENOENT) ) if bad_socket @socket = nil return end # Try once to reconnect if the socket has been closed retries ||= 1 if retries <= 1 && boom.is_a?(Errno::ENOTCONN) or retries <= 1 && boom.is_a?(IOError) && boom. =~ /closed stream/i retries += 1 begin @socket = connect retry rescue StandardError => e boom = e end end @logger.error { "Statsd: #{boom.class} #{boom}" } if @logger nil end |