Class: Puma::Plugin::TelemetryToo::SocketData

Inherits:
Object
  • Object
show all
Defined in:
lib/puma/plugin/telemetry_too/data.rb

Overview

Pulls TCP INFO data from socket

Constant Summary collapse

UNACKED_REGEXP =
/\ unacked=(?<unacked>\d+)\ /

Instance Method Summary collapse

Constructor Details

#initialize(ios, parser) ⇒ SocketData

Returns a new instance of SocketData.



121
122
123
124
125
126
127
128
129
# File 'lib/puma/plugin/telemetry_too/data.rb', line 121

def initialize(ios, parser)
  @sockets = ios.select { |io| io.respond_to?(:getsockopt) && io.is_a?(TCPSocket) }
  @parser =
    case parser
    when :inspect then method(:parse_with_inspect)
    when :unpack then method(:parse_with_unpack)
    when Proc then parser
    end
end

Instance Method Details

#metricsObject



141
142
143
144
145
# File 'lib/puma/plugin/telemetry_too/data.rb', line 141

def metrics
  {
    'sockets.backlog' => unacked
  }
end

#unackedObject

Number of unacknowledged connections in the sockets, which we know as socket backlog.



134
135
136
137
138
139
# File 'lib/puma/plugin/telemetry_too/data.rb', line 134

def unacked
  @sockets.sum do |socket|
    @parser.call(socket.getsockopt(Socket::SOL_TCP,
                                   Socket::TCP_INFO))
  end
end