memcached_exporter: Explicitly close memcached connection.

Fixes warnings like “ResourceWarning: unclosed <socket.socket fd=5,
family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0,
laddr=('127.0.0.1', 39702), raddr=('127.0.0.1', 11211)>” with warnings
enabled.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-07-16 13:33:59 -07:00 committed by Tim Abbott
parent c8eaceff21
commit f3c67103cf
1 changed files with 7 additions and 6 deletions

View File

@ -382,13 +382,14 @@ class MemcachedCollector(Collector):
raw_stats = client.stats("sizes")
sizes_stats = next(iter(raw_stats.values()))
if sizes_stats.get("sizes_status") == b"disabled" or sizes_stats == {}:
return
if sizes_stats.get("sizes_status") != b"disabled" and sizes_stats != {}:
sizes = sorted([int(x) for x in sizes_stats])
yield gauge(
"item_max_bytes", "Largest item (rounded to 32 bytes) in bytes.", value=sizes[-1]
)
client.disconnect_all()
if __name__ == "__main__":
REGISTRY.register(MemcachedCollector())