Class: StatsD::Instrument::UDPSink
- Inherits:
-
Object
- Object
- StatsD::Instrument::UDPSink
- 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
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(datagram) ⇒ Object
- #addr ⇒ Object
-
#initialize(host, port) ⇒ UDPSink
constructor
A new instance of UDPSink.
- #sample?(sample_rate) ⇒ Boolean
Constructor Details
#initialize(host, port) ⇒ UDPSink
Returns a new instance of UDPSink.
13 14 15 16 17 18 |
# File 'lib/statsd/instrument/udp_sink.rb', line 13 def initialize(host, port) @host = host @port = port @mutex = Mutex.new @socket = nil end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/statsd/instrument/udp_sink.rb', line 11 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'lib/statsd/instrument/udp_sink.rb', line 11 def port @port end |
Class Method Details
.for_addr(addr) ⇒ Object
6 7 8 9 |
# File 'lib/statsd/instrument/udp_sink.rb', line 6 def self.for_addr(addr) host, port_as_string = addr.split(':', 2) new(host, Integer(port_as_string)) end |
Instance Method Details
#<<(datagram) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/statsd/instrument/udp_sink.rb', line 24 def <<(datagram) with_socket { |socket| socket.send(datagram, 0) > 0 } self rescue ThreadError # In cases where a TERM or KILL signal has been sent, and we send stats as # part of a signal handler, locks cannot be acquired, so we do our best # to try and send the datagram without a lock. socket.send(datagram, 0) > 0 rescue SocketError, IOError, SystemCallError # TODO: log? invalidate_socket end |
#addr ⇒ Object
39 40 41 |
# File 'lib/statsd/instrument/udp_sink.rb', line 39 def addr "#{host}:#{port}" end |
#sample?(sample_rate) ⇒ Boolean
20 21 22 |
# File 'lib/statsd/instrument/udp_sink.rb', line 20 def sample?(sample_rate) sample_rate == 1 || rand < sample_rate end |