IO::MetricsSourceIOMetricsListener

class << Listener

Re-wire the top-level Listener.capture to prefer the native inet_diag path for TCP sockets while delegating Unix sockets to the pure-Ruby Linux implementation.

Nested

Definitions

def supported?

Whether native listener stats can be captured on this system.

Signature

returns Boolean

True when the inet_diag C extension is loaded.

Implementation

def supported?
	IO::Metrics::Listener::Native.supported?
end

def supported?

Signature

returns Boolean

False on platforms without a listener capture implementation.

Implementation

def supported?
	false
end

def capture(addresses: nil, paths: nil)

Signature

parameter addresses Array(String) | Nil

TCP address filter.

parameter paths Array(String) | Nil

Unix socket path filter.

Implementation

def capture(addresses: nil, paths: nil)
	result = []
	
	# TCP (native): all listeners when both arguments are omitted; skip only when `paths` is set and `addresses` is omitted (Unix-only capture), matching {IO::Metrics::Listener::Linux.capture}.
	if addresses || paths.nil?
		result.concat(IO::Metrics::Listener::Native.capture(addresses: addresses))
	end
	
	# Unix domain sockets (via `/proc/net/unix`): all listeners when both omitted; skip only when `addresses` is set and `paths` is omitted (TCP-only capture).
	if paths || addresses.nil?
		result.concat(IO::Metrics::Listener::Linux.capture_unix(paths))
	end
	
	return result
end

def capture(**options)

Signature

returns Nil

Listener capture is not available on this platform.

Implementation

def capture(**options)
	nil
end

def as_json(*)

Serialization for JSON; address uses Addrinfo#inspect_sockaddr.

Implementation

def as_json(*)
	{
		address: address&.inspect_sockaddr,
		queued_count: queued_count,
		active_count: active_count,
		close_wait_count: close_wait_count,
		fin_wait_count: fin_wait_count,
		time_wait_count: time_wait_count,
	}
end

def to_json(*arguments)

Convert the object to a JSON string.

Implementation

def to_json(*arguments)
	as_json.to_json(*arguments)
end

def self.zero

Create a zero-initialized Listener instance (no endpoint; for tests or templates).

Signature

returns Listener

Counters zero; #address is nil.

Implementation

def self.zero
	new(nil, 0, 0, 0, 0, 0)
end