Class: Datadog::Statsd::Connection
- Inherits:
-
Object
- Object
- Datadog::Statsd::Connection
- Defined in:
- lib/datadog/statsd/connection.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#close ⇒ Object
Close the underlying socket.
-
#initialize(telemetry) ⇒ Connection
constructor
A new instance of Connection.
- #write(payload) ⇒ Object
Constructor Details
#initialize(telemetry) ⇒ Connection
Returns a new instance of Connection.
6 7 8 |
# File 'lib/datadog/statsd/connection.rb', line 6 def initialize(telemetry) @telemetry = telemetry end |
Instance Method Details
#close ⇒ Object
Close the underlying socket
11 12 13 14 15 16 17 18 |
# File 'lib/datadog/statsd/connection.rb', line 11 def close begin @socket && @socket.close if instance_variable_defined?(:@socket) rescue StandardError => boom logger.error { "Statsd: #{boom.class} #{boom}" } if logger end @socket = nil end |
#write(payload) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/datadog/statsd/connection.rb', line 20 def write(payload) logger.debug { "Statsd: #{payload}" } if logger flush_telemetry = telemetry.flush? payload += telemetry.flush if flush_telemetry (payload) telemetry.reset if flush_telemetry telemetry.sent(packets: 1, bytes: payload.length) rescue StandardError => boom # Try once to reconnect if the socket has been closed retries ||= 1 if retries <= 1 && (boom.is_a?(Errno::ENOTCONN) or boom.is_a?(Errno::ECONNREFUSED) or boom.is_a?(IOError) && boom. =~ /closed stream/i) retries += 1 begin close retry rescue StandardError => e boom = e end end telemetry.dropped(packets: 1, bytes: payload.length) logger.error { "Statsd: #{boom.class} #{boom}" } if logger nil end |