class Observability::Sender::UDP

A sender that sends events as JSON over UDP.

Constants

RETRY_INTERVAL

Number of seconds to wait between retrying a blocked write

SERIALIZE_PIPELINE

The pipeline to use for turning events into network data

Attributes

socket[R]

The socket to send events over

Public Class Methods

new( * ) click to toggle source

Create a new UDP sender

# File lib/observability/sender/udp.rb, line 36
def initialize( * )
        @socket = UDPSocket.new
end

Public Instance Methods

send_event( data ) click to toggle source

Send the specified event.

# File lib/observability/sender/udp.rb, line 73
def send_event( data )
        until data.empty?
                bytes = self.socket.sendmsg_nonblock( data, 0, exception: false )

                if bytes == :wait_writable
                        IO.select( nil, [self.socket], nil )
                else
                        self.log.debug "Sent: %p" % [ data[0, bytes] ]
                        data[ 0, bytes ] = ''
                end
        end
end
serialize_events( events ) click to toggle source

Serialize each the given events and return the results.

# File lib/observability/sender/udp.rb, line 67
def serialize_events( events  )
        return events.map( &SERIALIZE_PIPELINE )
end
start() click to toggle source

Start sending queued events.

Calls superclass method Observability::Sender#start
# File lib/observability/sender/udp.rb, line 51
def start
        self.socket.connect( self.class.host, self.class.port )

        super
end
stop() click to toggle source

Stop the sender's executor.

Calls superclass method Observability::Sender#stop
# File lib/observability/sender/udp.rb, line 59
def stop
        super

        self.socket.shutdown( :WR )
end