Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add current_connections and peak_connections stats to TCP Input #163

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/logstash/inputs/tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def initialize(*args)
@client_socket = nil
@connection_sockets = {}
@socket_mutex = Mutex.new
@metric = @input.metric
@peak_connection_count = Concurrent::AtomicFixnum.new(0)

@ssl_context = nil
end
Expand Down Expand Up @@ -353,12 +355,25 @@ def server_socket
end

def add_connection_socket(socket)
@socket_mutex.synchronize{@connection_sockets[socket] = true}
@socket_mutex.synchronize{@connection_sockets[socket] = true; increment_connection_count}
socket
end

def delete_connection_socket(socket)
@socket_mutex.synchronize{@connection_sockets.delete(socket)}
@socket_mutex.synchronize{@connection_sockets.delete(socket); decrement_connection_count}
end

def increment_connection_count
current_connection_count = @connection_sockets.size
@metric.gauge(:current_connections, current_connection_count)
if current_connection_count > @peak_connection_count.value
@peak_connection_count.value = current_connection_count
@metric.gauge(:peak_connections, @peak_connection_count.value)
end
end

def decrement_connection_count
@metric.gauge(:current_connections, @connection_sockets.size)
end

def connection_sockets
Expand Down