Class: Datadog::Statsd::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/statsd.rb

Direct Known Subclasses

UDPConnection, UDSConnection

Constant Summary collapse

DEFAULT_HOST =
'127.0.0.1'
DEFAULT_PORT =
8125

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject (readonly)

StatsD host. Defaults to 127.0.0.1.



28
29
30
# File 'lib/datadog/statsd.rb', line 28

def host
  @host
end

#portObject (readonly)

StatsD port. Defaults to 8125.



31
32
33
# File 'lib/datadog/statsd.rb', line 31

def port
  @port
end

#socket_pathObject (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

#closeObject

Close the underlying socket



37
38
39
# File 'lib/datadog/statsd.rb', line 37

def close
  @socket && @socket.close
end

#write(message) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/datadog/statsd.rb', line 41

def write(message)
  @logger.debug { "Statsd: #{message}" } if @logger
  send_message(message)
rescue StandardError => boom
  # 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.message =~ /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