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. 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 connections in CLOSE_WAIT state (peer has closed; application still holds the socket).
-
#fin_wait_count ⇒ Object
readonly
Number of connections in FIN_WAIT1 or FIN_WAIT2 state (server has initiated close; peer has not yet completed close).
-
#queued_count ⇒ Object
readonly
Number of connections waiting to be accepted (currently in the accept queue).
-
#time_wait_count ⇒ Object
readonly
Number of connections in TIME_WAIT state (both sides closed; waiting ~60s for delayed packets before releasing the port/fd).
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.
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 50 51 52 53 54 |
# File 'lib/io/metrics/listener.rb', line 18 class Listener < Struct.new(:address, :queued_count, :active_count, :close_wait_count, :fin_wait_count, :time_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, fin_wait_count: fin_wait_count, time_wait_count: time_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, 0, 0) 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.
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 50 51 52 53 54 |
# File 'lib/io/metrics/listener.rb', line 18 class Listener < Struct.new(:address, :queued_count, :active_count, :close_wait_count, :fin_wait_count, :time_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, fin_wait_count: fin_wait_count, time_wait_count: time_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, 0, 0) 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 connections in CLOSE_WAIT state (peer has closed; application still holds the socket).
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 50 51 52 53 54 |
# File 'lib/io/metrics/listener.rb', line 18 class Listener < Struct.new(:address, :queued_count, :active_count, :close_wait_count, :fin_wait_count, :time_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, fin_wait_count: fin_wait_count, time_wait_count: time_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, 0, 0) 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 |
#fin_wait_count ⇒ Object (readonly)
Number of connections in FIN_WAIT1 or FIN_WAIT2 state (server has initiated close; peer has not yet completed close).
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 50 51 52 53 54 |
# File 'lib/io/metrics/listener.rb', line 18 class Listener < Struct.new(:address, :queued_count, :active_count, :close_wait_count, :fin_wait_count, :time_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, fin_wait_count: fin_wait_count, time_wait_count: time_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, 0, 0) 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).
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 50 51 52 53 54 |
# File 'lib/io/metrics/listener.rb', line 18 class Listener < Struct.new(:address, :queued_count, :active_count, :close_wait_count, :fin_wait_count, :time_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, fin_wait_count: fin_wait_count, time_wait_count: time_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, 0, 0) 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 |
#time_wait_count ⇒ Object (readonly)
Number of connections in TIME_WAIT state (both sides closed; waiting ~60s for delayed packets before releasing the port/fd).
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 50 51 52 53 54 |
# File 'lib/io/metrics/listener.rb', line 18 class Listener < Struct.new(:address, :queued_count, :active_count, :close_wait_count, :fin_wait_count, :time_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, fin_wait_count: fin_wait_count, time_wait_count: time_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, 0, 0) 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).
51 52 53 |
# File 'lib/io/metrics/listener.rb', line 51 def self.capture(**) return nil end |
.supported? ⇒ Boolean
Whether listener capture is supported on this platform.
43 44 45 |
# File 'lib/io/metrics/listener.rb', line 43 def self.supported? false end |
.zero ⇒ Object
Create a zero-initialized Listener instance (no endpoint; for tests or templates).
38 39 40 |
# File 'lib/io/metrics/listener.rb', line 38 def self.zero new(nil, 0, 0, 0, 0, 0) end |
Instance Method Details
#as_json ⇒ Object
Serialize for JSON; address uses Addrinfo#inspect_sockaddr.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/io/metrics/listener.rb', line 20 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 |
#to_json(*arguments) ⇒ Object
Convert the object to a JSON string.
32 33 34 |
# File 'lib/io/metrics/listener.rb', line 32 def to_json(*arguments) as_json.to_json(*arguments) end |