Class: StatsD::Instrument::Sink
- Inherits:
-
Object
- Object
- StatsD::Instrument::Sink
- Defined in:
- lib/statsd/instrument/sink.rb
Constant Summary collapse
- FINALIZER =
->(object_id) do Thread.list.each do |thread| if (store = thread["StatsD::UDPSink"]) store.delete(object_id)&.close end end end
Class Method Summary collapse
Instance Method Summary collapse
- #<<(datagram) ⇒ Object
- #connection ⇒ Object
- #connection_type ⇒ Object
- #flush(blocking: false) ⇒ Object
- #host ⇒ Object
-
#initialize(connection = nil) ⇒ Sink
constructor
A new instance of Sink.
- #port ⇒ Object
- #sample?(sample_rate) ⇒ Boolean
Constructor Details
Class Method Details
.for_addr(addr) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/statsd/instrument/sink.rb', line 7 def for_addr(addr) # if addr is host:port if addr.include?(":") host, port_as_string = addr.split(":", 2) connection = UdpConnection.new(host, Integer(port_as_string)) new(connection) else connection = UdsConnection.new(addr) new(connection) end end |
Instance Method Details
#<<(datagram) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/statsd/instrument/sink.rb', line 37 def <<(datagram) retried = false begin connection.send_datagram(datagram) rescue SocketError, IOError, SystemCallError => error StatsD.logger.debug do "[#{self.class.name}] Resetting connection because of #{error.class}: #{error.}" end invalidate_connection if retried StatsD.logger.warn do "[#{self.class.name}] Events were dropped because of #{error.class}: #{error.}" end else retried = true retry end end self end |
#connection ⇒ Object
66 67 68 |
# File 'lib/statsd/instrument/sink.rb', line 66 def connection thread_store[object_id] ||= @connection end |
#connection_type ⇒ Object
62 63 64 |
# File 'lib/statsd/instrument/sink.rb', line 62 def connection_type connection.class.name end |
#flush(blocking: false) ⇒ Object
58 59 60 |
# File 'lib/statsd/instrument/sink.rb', line 58 def flush(blocking: false) # noop end |
#host ⇒ Object
70 71 72 |
# File 'lib/statsd/instrument/sink.rb', line 70 def host connection.host end |
#port ⇒ Object
74 75 76 |
# File 'lib/statsd/instrument/sink.rb', line 74 def port connection.port end |
#sample?(sample_rate) ⇒ Boolean
33 34 35 |
# File 'lib/statsd/instrument/sink.rb', line 33 def sample?(sample_rate) sample_rate == 1.0 || rand < sample_rate end |