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: Dispatcher
Constant Summary collapse
- DEFAULT_FLUSH_INTERVAL =
1.0- DEFAULT_THREAD_PRIORITY =
100- DEFAULT_FLUSH_THRESHOLD =
50- 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, flush_interval: DEFAULT_FLUSH_INTERVAL, thread_priority: DEFAULT_THREAD_PRIORITY, flush_threshold: DEFAULT_FLUSH_THRESHOLD, 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, flush_interval: DEFAULT_FLUSH_INTERVAL, thread_priority: DEFAULT_THREAD_PRIORITY, flush_threshold: DEFAULT_FLUSH_THRESHOLD, buffer_capacity: DEFAULT_BUFFER_CAPACITY, max_packet_size: DEFAULT_MAX_PACKET_SIZE) ⇒ BatchedUDPSink
Returns a new instance of BatchedUDPSink.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 28 def initialize( host, port, flush_interval: DEFAULT_FLUSH_INTERVAL, thread_priority: DEFAULT_THREAD_PRIORITY, flush_threshold: DEFAULT_FLUSH_THRESHOLD, buffer_capacity: DEFAULT_BUFFER_CAPACITY, max_packet_size: DEFAULT_MAX_PACKET_SIZE ) @host = host @port = port @dispatcher = Dispatcher.new( host, port, flush_interval, flush_threshold, 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.
20 21 22 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 20 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
20 21 22 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 20 def port @port end |
Class Method Details
.finalize(dispatcher) ⇒ Object
23 24 25 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 23 def finalize(dispatcher) proc { dispatcher.shutdown } end |
.for_addr(addr, **kwargs) ⇒ Object
15 16 17 18 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 15 def self.for_addr(addr, **kwargs) host, port_as_string = addr.split(":", 2) new(host, Integer(port_as_string), **kwargs) end |
Instance Method Details
#<<(datagram) ⇒ Object
55 56 57 58 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 55 def <<(datagram) @dispatcher << datagram self end |
#sample?(sample_rate) ⇒ Boolean
51 52 53 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 51 def sample?(sample_rate) sample_rate == 1.0 || rand < sample_rate end |
#shutdown(*args) ⇒ Object
60 61 62 |
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 60 def shutdown(*args) @dispatcher.shutdown(*args) end |