class Arborist::Monitor::Socket::UDP
Constants
- USED_PROPERTIES
Always request the node addresses and port.
Public Class Methods
new( timeout: Arborist::Monitor::Socket.default_timeout, batch_size: Arborist::Monitor::Socket.batch_size )
click to toggle source
Create a new UDP
monitor with the specified options
. Valid options are:
:timeout
Set the number of seconds to wait for a connection for each node.
:batch_size
The number of UDP connection attempts to perform simultaneously.
# File lib/arborist/monitor/socket.rb, line 159 def initialize( timeout: Arborist::Monitor::Socket.default_timeout, batch_size: Arborist::Monitor::Socket.batch_size ) self.timeout = timeout self.batch_size = batch_size end
node_properties()
click to toggle source
Return the properties used by this monitor.
# File lib/arborist/monitor/socket.rb, line 148 def self::node_properties return USED_PROPERTIES end
run( nodes )
click to toggle source
Instantiate a monitor check and run it for the specified nodes
.
# File lib/arborist/monitor/socket.rb, line 142 def self::run( nodes ) return self.new.run( nodes ) end
Public Instance Methods
make_connections_enum( nodes )
click to toggle source
Open a socket for each of the specified nodes and return a Hash of the sockets (or the error from the connection attempt) keyed by node identifier.
# File lib/arborist/monitor/socket.rb, line 172 def make_connections_enum( nodes ) return nodes.lazy.map do |identifier, node_data| address = node_data['addresses'].first port = node_data['port'] self.log.debug "Creating UDP connection for %s:%d" % [ address, port ] sock = Socket.new( :INET, :DGRAM ) conn = begin sockaddr = Socket.sockaddr_in( port, address ) sock.connect( sockaddr ) sock.send( '', 0 ) sock.recvfrom_nonblock( 1 ) sock rescue Errno::EAGAIN self.log.debug " connection started" sock rescue => err self.log.error " %p setting up connection: %s" % [ err.class, err.message ] err end self.log.debug "UDP connection object is: %p" % [ conn ] { conn: conn, identifier: identifier } end end
status_for_conn( conn_hash, duration )
click to toggle source
Build a status for the specified conn_hash
after its :conn has indicated it is ready.
# File lib/arborist/monitor/socket.rb, line 202 def status_for_conn( conn_hash, duration ) sock = conn_hash[:conn] sock.recvfrom_nonblock( 1 ) return { udp_socket_connect: { duration: duration } } rescue Errno::EAGAIN return { udp_socket_connect: { duration: duration } } rescue SocketError, SystemCallError => err self.log.debug "Got %p while connecting to %s" % [ err.class, conn_hash[:identifier] ] return { error: err.message } ensure sock.close if sock end