Class: StatsD::Instrument::BatchedUDPSink
- Inherits:
-
Object
- Object
- StatsD::Instrument::BatchedUDPSink
- Defined in:
- lib/statsd/instrument/batched_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.
Defined Under Namespace
Classes: Buffer, Dispatcher
Constant Summary collapse
- DEFAULT_THREAD_PRIORITY =
100
- DEFAULT_BUFFER_CAPACITY =
5_000
- DEFAULT_MAX_PACKET_SIZE =
1472
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, thread_priority: DEFAULT_THREAD_PRIORITY, buffer_capacity: DEFAULT_BUFFER_CAPACITY, max_packet_size: DEFAULT_MAX_PACKET_SIZE) ⇒ BatchedUDPSink
constructor
A new instance of BatchedUDPSink.
- #sample?(sample_rate) ⇒ Boolean
- #shutdown(*args) ⇒ Object
Constructor Details
#initialize(host, port, thread_priority: DEFAULT_THREAD_PRIORITY, buffer_capacity: DEFAULT_BUFFER_CAPACITY, max_packet_size: DEFAULT_MAX_PACKET_SIZE) ⇒ BatchedUDPSink
Returns a new instance of BatchedUDPSink.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 26 def initialize( host, port, thread_priority: DEFAULT_THREAD_PRIORITY, buffer_capacity: DEFAULT_BUFFER_CAPACITY, max_packet_size: DEFAULT_MAX_PACKET_SIZE ) @host = host @port = port @dispatcher = Dispatcher.new( host, port, buffer_capacity, thread_priority, max_packet_size, ) ObjectSpace.define_finalizer(self, self.class.finalize(@dispatcher)) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
13 14 15 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 13 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
13 14 15 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 13 def port @port end |
Class Method Details
.finalize(dispatcher) ⇒ Object
21 22 23 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 21 def finalize(dispatcher) proc { dispatcher.shutdown } end |
.for_addr(addr, **kwargs) ⇒ Object
16 17 18 19 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 16 def for_addr(addr, **kwargs) host, port_as_string = addr.split(":", 2) new(host, Integer(port_as_string), **kwargs) end |
Instance Method Details
#<<(datagram) ⇒ Object
49 50 51 52 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 49 def <<(datagram) @dispatcher << datagram self end |
#sample?(sample_rate) ⇒ Boolean
45 46 47 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 45 def sample?(sample_rate) sample_rate == 1.0 || rand < sample_rate end |
#shutdown(*args) ⇒ Object
54 55 56 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 54 def shutdown(*args) @dispatcher.shutdown(*args) end |