Skip to content

Commit

Permalink
Do not emit backlog metric if its unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
raags committed Nov 14, 2023
1 parent b980c0d commit 9e308f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion gunicorn/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,11 @@ def manage_workers(self):
"value": active_worker_count,
"mtype": "gauge"})

backlog = sum([sock.get_backlog() for sock in self.LISTENERS])
backlog = sum([
sock.get_backlog()
for sock in self.LISTENERS
if sock.get_backlog() is not None
])
if backlog:
self.log.debug("socket backlog: {0}".format(backlog),
extra={"metric": "gunicorn.backlog",
Expand Down
8 changes: 5 additions & 3 deletions gunicorn/sock.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def close(self):
self.sock = None

def get_backlog(self):
return 0
return None


class TCPSocket(BaseSocket):
Expand All @@ -100,12 +100,14 @@ def get_backlog(self):
fmt = 'B'*8+'I'*24
try:
tcp_info_struct = self.sock.getsockopt(socket.IPPROTO_TCP,
socket.TCP_INFO, 104)
socket.TCP_INFO, 104)
# 12 is tcpi_unacked
return struct.unpack(fmt, tcp_info_struct)[12]
except AttributeError:
pass
return 0

return None


class TCP6Socket(TCPSocket):

Expand Down

0 comments on commit 9e308f5

Please sign in to comment.