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.
Constant Summary collapse
- FINALIZER =
->(object_id) do Thread.list.each do |thread| if (store = thread["StatsD::UDPSink"]) store.delete(object_id)&.close end end end
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
-
#initialize(host, port) ⇒ UDPSink
constructor
A new instance of UDPSink.
- #sample?(sample_rate) ⇒ Boolean
Constructor Details
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
15 16 17 |
# File 'lib/statsd/instrument/udp_sink.rb', line 15 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
15 16 17 |
# File 'lib/statsd/instrument/udp_sink.rb', line 15 def port @port end |
Class Method Details
.for_addr(addr) ⇒ Object
9 10 11 12 |
# File 'lib/statsd/instrument/udp_sink.rb', line 9 def for_addr(addr) host, port_as_string = addr.split(":", 2) new(host, Integer(port_as_string)) end |
Instance Method Details
#<<(datagram) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/statsd/instrument/udp_sink.rb', line 35 def <<(datagram) retried = false begin socket.send(datagram, 0) rescue SocketError, IOError, SystemCallError => error StatsD.logger.debug do "[StatsD::Instrument::UDPSink] Resetting connection because of #{error.class}: #{error.}" end invalidate_socket if retried StatsD.logger.warn do "[#{self.class.name}] Events were dropped because of #{error.class}: #{error.}" end else retried = true retry end end self end |
#sample?(sample_rate) ⇒ Boolean
31 32 33 |
# File 'lib/statsd/instrument/udp_sink.rb', line 31 def sample?(sample_rate) sample_rate == 1.0 || rand < sample_rate end |