Class: StatsD::Instrument::BatchedUDPSink

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#portObject (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

#flush(blocking:) ⇒ Object



58
59
60
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 58

def flush(blocking:)
  @dispatcher.flush(blocking: blocking)
end

#sample?(sample_rate) ⇒ Boolean

Returns:

  • (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