Class: StatsD::Instrument::BatchedSink

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/statsd/instrument/batched_sink.rb

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sink, thread_priority: DEFAULT_THREAD_PRIORITY, buffer_capacity: DEFAULT_BUFFER_CAPACITY, max_packet_size: DEFAULT_MAX_PACKET_SIZE, statistics_interval: DEFAULT_STATISTICS_INTERVAL) ⇒ BatchedSink

Returns a new instance of BatchedSink.



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

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

Class Method Details

.finalize(dispatcher) ⇒ Object



25
26
27
# File 'lib/statsd/instrument/batched_sink.rb', line 25

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

.for_addr(addr, **kwargs) ⇒ Object



20
21
22
23
# File 'lib/statsd/instrument/batched_sink.rb', line 20

def for_addr(addr, **kwargs)
  sink = StatsD::Instrument::Sink.for_addr(addr)
  new(sink, **kwargs)
end

Instance Method Details

#<<(datagram) ⇒ Object



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

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

#connectionObject



65
66
67
# File 'lib/statsd/instrument/batched_sink.rb', line 65

def connection
  @sink.connection
end

#flush(blocking:) ⇒ Object



61
62
63
# File 'lib/statsd/instrument/batched_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_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_sink.rb', line 57

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