Class: StatsD::Instrument::UDPSink

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

Overview

Note:

This class is part of the new Client implementation that is intended to become the new default in the next major release of this library.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ UDPSink

Returns a new instance of UDPSink.



15
16
17
18
19
20
# File 'lib/statsd/instrument/udp_sink.rb', line 15

def initialize(host, port)
  @host = host
  @port = port
  @mutex = Mutex.new
  @socket = nil
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



13
14
15
# File 'lib/statsd/instrument/udp_sink.rb', line 13

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



13
14
15
# File 'lib/statsd/instrument/udp_sink.rb', line 13

def port
  @port
end

Class Method Details

.for_addr(addr) ⇒ Object



8
9
10
11
# File 'lib/statsd/instrument/udp_sink.rb', line 8

def self.for_addr(addr)
  host, port_as_string = addr.split(":", 2)
  new(host, Integer(port_as_string))
end

Instance Method Details

#<<(datagram) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/statsd/instrument/udp_sink.rb', line 26

def <<(datagram)
  with_socket { |socket| socket.send(datagram, 0) }
  self
rescue SocketError, IOError, SystemCallError => error
  StatsD.logger.debug do
    "[StatsD::Instrument::UDPSink] Resetting connection because of #{error.class}: #{error.message}"
  end
  invalidate_socket
  self
end

#sample?(sample_rate) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/statsd/instrument/udp_sink.rb', line 22

def sample?(sample_rate)
  sample_rate == 1.0 || rand < sample_rate
end