Class: IO::Metrics::Listener
- Inherits:
-
Struct
- Object
- Struct
- IO::Metrics::Listener
- Defined in:
- lib/io/metrics/listener.rb
Overview
Represents a network listener socket with its queue statistics.
Defined Under Namespace
Instance Attribute Summary collapse
-
#active_count ⇒ Object
readonly
Number of accepted connections in ESTABLISHED state.
-
#address ⇒ Object
readonly
Listening endpoint from capture; nil only for Listener.zero placeholders.
-
#close_wait_count ⇒ Object
readonly
Number of accepted connections in CLOSE_WAIT state (peer has closed; application still processing).
-
#queued_count ⇒ Object
readonly
Number of connections waiting to be accepted (currently in the accept queue).
Class Method Summary collapse
-
.capture(**options) ⇒ Object
Capture listener listeners for the given address(es).
-
.supported? ⇒ Boolean
Whether listener capture is supported on this platform.
-
.zero ⇒ Object
Create a zero-initialized Listener instance (no endpoint; for tests or templates).
Instance Method Summary collapse
-
#as_json ⇒ Object
Serialize for JSON; address uses Addrinfo#inspect_sockaddr.
-
#to_json(*arguments) ⇒ Object
Convert the object to a JSON string.
Instance Attribute Details
#active_count ⇒ Object (readonly)
Number of accepted connections in ESTABLISHED state.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/io/metrics/listener.rb', line 15 class Listener < Struct.new(:address, :queued_count, :active_count, :close_wait_count) # Serialize for JSON; address uses Addrinfo#inspect_sockaddr. def as_json(*) { address: address&.inspect_sockaddr, queued_count: queued_count, active_count: active_count, close_wait_count: close_wait_count, } end # Convert the object to a JSON string. def to_json(*arguments) as_json.to_json(*arguments) end # Create a zero-initialized Listener instance (no endpoint; for tests or templates). # @returns [Listener] Counters zero; {#address} is nil. def self.zero new(nil, 0, 0, 0) # address, queued_count, active_count, close_wait_count end # Whether listener stats can be captured on this system. def self.supported? false end # Capture listener stats for the given address(es). # @parameter addresses [Array(String) | Nil] TCP address(es) to capture, e.g. ["0.0.0.0:80"]. If nil, captures all listening TCP sockets. # @parameter paths [Array(String) | Nil] Unix socket path(s) to capture. If nil and addresses is nil, captures all. If nil but addresses specified, captures none. # @returns [Array(Listener) | Nil] Captured listeners, or nil if not supported. def self.capture(**) return nil end end |
#address ⇒ Object (readonly)
Listening endpoint from capture; nil only for zero placeholders.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/io/metrics/listener.rb', line 15 class Listener < Struct.new(:address, :queued_count, :active_count, :close_wait_count) # Serialize for JSON; address uses Addrinfo#inspect_sockaddr. def as_json(*) { address: address&.inspect_sockaddr, queued_count: queued_count, active_count: active_count, close_wait_count: close_wait_count, } end # Convert the object to a JSON string. def to_json(*arguments) as_json.to_json(*arguments) end # Create a zero-initialized Listener instance (no endpoint; for tests or templates). # @returns [Listener] Counters zero; {#address} is nil. def self.zero new(nil, 0, 0, 0) # address, queued_count, active_count, close_wait_count end # Whether listener stats can be captured on this system. def self.supported? false end # Capture listener stats for the given address(es). # @parameter addresses [Array(String) | Nil] TCP address(es) to capture, e.g. ["0.0.0.0:80"]. If nil, captures all listening TCP sockets. # @parameter paths [Array(String) | Nil] Unix socket path(s) to capture. If nil and addresses is nil, captures all. If nil but addresses specified, captures none. # @returns [Array(Listener) | Nil] Captured listeners, or nil if not supported. def self.capture(**) return nil end end |
#close_wait_count ⇒ Object (readonly)
Number of accepted connections in CLOSE_WAIT state (peer has closed; application still processing).
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/io/metrics/listener.rb', line 15 class Listener < Struct.new(:address, :queued_count, :active_count, :close_wait_count) # Serialize for JSON; address uses Addrinfo#inspect_sockaddr. def as_json(*) { address: address&.inspect_sockaddr, queued_count: queued_count, active_count: active_count, close_wait_count: close_wait_count, } end # Convert the object to a JSON string. def to_json(*arguments) as_json.to_json(*arguments) end # Create a zero-initialized Listener instance (no endpoint; for tests or templates). # @returns [Listener] Counters zero; {#address} is nil. def self.zero new(nil, 0, 0, 0) # address, queued_count, active_count, close_wait_count end # Whether listener stats can be captured on this system. def self.supported? false end # Capture listener stats for the given address(es). # @parameter addresses [Array(String) | Nil] TCP address(es) to capture, e.g. ["0.0.0.0:80"]. If nil, captures all listening TCP sockets. # @parameter paths [Array(String) | Nil] Unix socket path(s) to capture. If nil and addresses is nil, captures all. If nil but addresses specified, captures none. # @returns [Array(Listener) | Nil] Captured listeners, or nil if not supported. def self.capture(**) return nil end end |
#queued_count ⇒ Object (readonly)
Number of connections waiting to be accepted (currently in the accept queue).
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/io/metrics/listener.rb', line 15 class Listener < Struct.new(:address, :queued_count, :active_count, :close_wait_count) # Serialize for JSON; address uses Addrinfo#inspect_sockaddr. def as_json(*) { address: address&.inspect_sockaddr, queued_count: queued_count, active_count: active_count, close_wait_count: close_wait_count, } end # Convert the object to a JSON string. def to_json(*arguments) as_json.to_json(*arguments) end # Create a zero-initialized Listener instance (no endpoint; for tests or templates). # @returns [Listener] Counters zero; {#address} is nil. def self.zero new(nil, 0, 0, 0) # address, queued_count, active_count, close_wait_count end # Whether listener stats can be captured on this system. def self.supported? false end # Capture listener stats for the given address(es). # @parameter addresses [Array(String) | Nil] TCP address(es) to capture, e.g. ["0.0.0.0:80"]. If nil, captures all listening TCP sockets. # @parameter paths [Array(String) | Nil] Unix socket path(s) to capture. If nil and addresses is nil, captures all. If nil but addresses specified, captures none. # @returns [Array(Listener) | Nil] Captured listeners, or nil if not supported. def self.capture(**) return nil end end |
Class Method Details
.capture(**options) ⇒ Object
Capture listener listeners for the given address(es).
46 47 48 |
# File 'lib/io/metrics/listener.rb', line 46 def self.capture(**) return nil end |
.supported? ⇒ Boolean
Whether listener capture is supported on this platform.
38 39 40 |
# File 'lib/io/metrics/listener.rb', line 38 def self.supported? false end |
.zero ⇒ Object
Create a zero-initialized Listener instance (no endpoint; for tests or templates).
33 34 35 |
# File 'lib/io/metrics/listener.rb', line 33 def self.zero new(nil, 0, 0, 0) # address, queued_count, active_count, close_wait_count end |
Instance Method Details
#as_json ⇒ Object
Serialize for JSON; address uses Addrinfo#inspect_sockaddr.
17 18 19 20 21 22 23 24 |
# File 'lib/io/metrics/listener.rb', line 17 def as_json(*) { address: address&.inspect_sockaddr, queued_count: queued_count, active_count: active_count, close_wait_count: close_wait_count, } end |
#to_json(*arguments) ⇒ Object
Convert the object to a JSON string.
27 28 29 |
# File 'lib/io/metrics/listener.rb', line 27 def to_json(*arguments) as_json.to_json(*arguments) end |