class Observability::Sender::UdpMulticast
A sender that sends events as JSON over multicast 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
multicast_address[R]
The address of the multicast group to send to
port[R]
The port to send on
socket[R]
The socket to send events over
Public Class Methods
bind_addr()
click to toggle source
Return an IPAddr that represents the local + multicast addresses to bind to.
# File lib/observability/sender/udp_multicast.rb, line 43 def self::bind_addr return IPAddr.new( self.bind_address ).hton + IPAddr.new( self.multicast_address ).hton end
new( * )
click to toggle source
Create a new UDP sender
# File lib/observability/sender/udp_multicast.rb, line 49 def initialize( * ) @multicast_address = self.class.multicast_address @port = self.class.port @socket = self.create_socket end
Public Instance Methods
create_socket()
click to toggle source
Create and return a UDPSocket after setting it up for multicast.
# File lib/observability/sender/udp_multicast.rb, line 100 def create_socket iaddr = self.class.bind_addr socket = UDPSocket.new socket.setsockopt( :IPPROTO_IP, :IP_ADD_MEMBERSHIP, iaddr ) socket.setsockopt( :IPPROTO_IP, :IP_MULTICAST_TTL, self.class.multicast_ttl ) socket.setsockopt( :IPPROTO_IP, :IP_MULTICAST_LOOP, 1 ) socket.setsockopt( :SOL_SOCKET, :SO_REUSEPORT, 1 ) return socket end
send_event( data )
click to toggle source
Send the specified event
.
# File lib/observability/sender/udp_multicast.rb, line 88 def send_event( data ) until data.empty? bytes = self.socket.send( data, 0, self.multicast_address, self.port ) self.log.debug "Sent: %p" % [ data[0, bytes] ] data[ 0, bytes ] = '' end end
serialize_events( events )
click to toggle source
Serialize each the given events
and return the results.
# File lib/observability/sender/udp_multicast.rb, line 82 def serialize_events( events ) return events.map( &SERIALIZE_PIPELINE ) end
stop()
click to toggle source
Stop the sender's executor.
Calls superclass method
Observability::Sender#stop
# File lib/observability/sender/udp_multicast.rb, line 74 def stop super self.socket.shutdown( :WR ) end