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, DispatcherStats

Constant Summary collapse

DEFAULT_THREAD_PRIORITY =
100
DEFAULT_BUFFER_CAPACITY =
5_000
DEFAULT_MAX_PACKET_SIZE =
1472
DEFAULT_STATISTICS_INTERVAL =

in seconds, and 0 implies disabled-by-default.

0

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, statistics_interval: DEFAULT_STATISTICS_INTERVAL) ⇒ BatchedUDPSink

Returns a new instance of BatchedUDPSink.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 27

def initialize(
  host,
  port,
  thread_priority: DEFAULT_THREAD_PRIORITY,
  buffer_capacity: DEFAULT_BUFFER_CAPACITY,
  max_packet_size: DEFAULT_MAX_PACKET_SIZE,
  statistics_interval: DEFAULT_STATISTICS_INTERVAL
)
  @host = host
  @port = port
  @dispatcher = Dispatcher.new(
    host,
    port,
    buffer_capacity,
    thread_priority,
    max_packet_size,
    statistics_interval,
  )
  ObjectSpace.define_finalizer(self, self.class.finalize(@dispatcher))
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Class Method Details

.finalize(dispatcher) ⇒ Object



22
23
24
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 22

def finalize(dispatcher)
  proc { dispatcher.shutdown }
end

.for_addr(addr, **kwargs) ⇒ Object



17
18
19
20
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 17

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



52
53
54
55
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 52

def <<(datagram)
  @dispatcher << datagram
  self
end

#flush(blocking:) ⇒ Object



61
62
63
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 61

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

#sample?(sample_rate) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 48

def sample?(sample_rate)
  sample_rate == 1.0 || rand < sample_rate
end

#shutdown(*args) ⇒ Object



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

def shutdown(*args)
  @dispatcher.shutdown(*args)
end