From 9e308f5dd00d31273e3a515b11943d28d3bfc088 Mon Sep 17 00:00:00 2001 From: Raghu Udiyar Date: Sun, 17 Jan 2021 19:55:25 +0530 Subject: [PATCH] Do not emit backlog metric if its unsupported --- gunicorn/arbiter.py | 6 +++++- gunicorn/sock.py | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index 635826d5a..341844811 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -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", diff --git a/gunicorn/sock.py b/gunicorn/sock.py index 628e27e1b..747199d1c 100644 --- a/gunicorn/sock.py +++ b/gunicorn/sock.py @@ -74,7 +74,7 @@ def close(self): self.sock = None def get_backlog(self): - return 0 + return None class TCPSocket(BaseSocket): @@ -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):