UDP

class
Superclass
Observability::Sender
Extended With
Configurability

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

anchor
new( * )

Create a new UDP sender

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

Public Instance Methods

anchor
send_event( data )

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
anchor
serialize_events( events )

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
anchor
start()

Start sending queued events.

# File lib/observability/sender/udp.rb, line 51
def start
        self.socket.connect( self.class.host, self.class.port )

        super
end
anchor
stop()

Stop the sender's executor.

# File lib/observability/sender/udp.rb, line 59
def stop
        super

        self.socket.shutdown( :WR )
end