From 5d5b4b48265cd755c0d805d9045c16152ac9555e Mon Sep 17 00:00:00 2001 From: Ainsey11 Date: Fri, 15 Apr 2022 01:44:29 +0100 Subject: [PATCH 1/2] Adding in es.close() to prevent memory/connection leaks over time --- tubearchivist-metrics/esconnect.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tubearchivist-metrics/esconnect.py b/tubearchivist-metrics/esconnect.py index 07abfe5..38ead53 100644 --- a/tubearchivist-metrics/esconnect.py +++ b/tubearchivist-metrics/esconnect.py @@ -56,4 +56,5 @@ class ElasticWrapper: print("Sleeping for 10 seconds...") sleep(10) else: + es.close() return response From af9d892857705a9874e1dab143f8553e5fbe282a Mon Sep 17 00:00:00 2001 From: Ainsey11 Date: Tue, 3 May 2022 02:24:09 +0100 Subject: [PATCH 2/2] re-formatting prints to utilise printf --- tubearchivist-metrics/getmetrics.py | 2 +- tubearchivist-metrics/main.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tubearchivist-metrics/getmetrics.py b/tubearchivist-metrics/getmetrics.py index 21497b0..a02282a 100644 --- a/tubearchivist-metrics/getmetrics.py +++ b/tubearchivist-metrics/getmetrics.py @@ -7,5 +7,5 @@ class GetMetrics: """Get count of documents from ES""" result = ElasticWrapper.get_count(index_name) - print("Metric for " + index_name + ": " + str(result)) + print(f"Metric for {index_name}: {result}") return int(result) diff --git a/tubearchivist-metrics/main.py b/tubearchivist-metrics/main.py index 59cc207..d729b4b 100644 --- a/tubearchivist-metrics/main.py +++ b/tubearchivist-metrics/main.py @@ -9,9 +9,9 @@ config = AppConfig().config # Print configuration on console when starting the application print("Configuration is currently set to:") -print("Elasticsearch URL: " + config["es_url"]) -print("Listen Port: " + config["listen_port"]) -print("Poll Interval (seconds): " + config["poll_interval"]) +print(f'Elasticsearch URL: {config["es_url"]}') +print(f'Listen Port: {config["listen_port"]}') +print(f'Polling interval (seconds): {config["poll_interval"]}') class AppMetrics: