From afa6d7f37b9735b410fa7b460d7c79808108854c Mon Sep 17 00:00:00 2001 From: psitem <5166927+psitem@users.noreply.github.com> Date: Fri, 5 Apr 2024 10:32:12 -0400 Subject: [PATCH 1/2] Fixes #1 Read the response buffer directly, one line at a time, instead of iterating on response.text. --- code/code.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 7146b15..7239408 100644 --- a/code/code.py +++ b/code/code.py @@ -310,9 +310,12 @@ def action_Up(): resptxt = response.text response.close() - for line in io.StringIO(resptxt): + while(response._received_length > 0): ## HELP monitor_status Monitor Status (1 = UP, 0= DOWN, 2= PENDING, 3= MAINTENANCE) ## monitor_status{monitor_name="name",monitor_type="http",monitor_url="http://mynameisurl",monitor_hostname="null",monitor_port="null"} 1 + linebytes = response._readto(b"\n") + line = linebytes.decode() + res = reobj.match(line) if ( res ): if ( res.group(1) == '0' ): @@ -361,6 +364,8 @@ def action_Up(): response = None requests = None + line = None + linebytes = None resptxt = None response = None requests = None From 96ee32df287efbc299663169e58d82aff5b67e08 Mon Sep 17 00:00:00 2001 From: psitem <5166927+psitem@users.noreply.github.com> Date: Fri, 5 Apr 2024 10:41:19 -0400 Subject: [PATCH 2/2] Update code.py --- code/code.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/code/code.py b/code/code.py index 7239408..56273fb 100644 --- a/code/code.py +++ b/code/code.py @@ -307,9 +307,6 @@ def action_Up(): action_Unreachable() else: - resptxt = response.text - response.close() - while(response._received_length > 0): ## HELP monitor_status Monitor Status (1 = UP, 0= DOWN, 2= PENDING, 3= MAINTENANCE) ## monitor_status{monitor_name="name",monitor_type="http",monitor_url="http://mynameisurl",monitor_hostname="null",monitor_port="null"} 1 @@ -330,6 +327,8 @@ def action_Up(): # print(res.group(1)) pass + response.close() + print("") print("Loopcount: " + f'{loopcount:>9}') print("Memory free: " + f'{gc.mem_free():>7}')