From fc692d5b5731e67663740173bd34a063a3825cb2 Mon Sep 17 00:00:00 2001 From: Daniel Pupius Date: Thu, 21 Nov 2024 17:29:19 -0800 Subject: [PATCH] Extra logging around healthchecks --- .vscode/settings.json | 16 ++++++++++++++++ check-mate.py | 20 ++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..85e2845 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,16 @@ +{ + "cSpell.words": [ + "healthcheck", + "healthchecks", + "HEALTHCHECKURL", + "jsonlogger", + "levelname", + "Meshtastic", + "NODEINFO", + "portnum", + "portnums", + "pythonjsonlogger", + "radiocheck", + "rssi" + ] +} diff --git a/check-mate.py b/check-mate.py index 54351de..6af19da 100644 --- a/check-mate.py +++ b/check-mate.py @@ -182,19 +182,31 @@ def onReceive(self, packet, interface): def reportHealth(self): if self.healthCheckURL is not None: + timeSinceLastHealthcheck = time.time() - self.lastHealthCheck if ( self.lastHealthCheck is None - or time.time() - self.lastHealthCheck > HEALTH_CHECK_THROTTLE + or timeSinceLastHealthcheck > HEALTH_CHECK_THROTTLE ): self.lastHealthCheck = time.time() response = requests.head(self.healthCheckURL) if response.status_code == 200: - self.logger.info("Healthcheck ❤️") + self.logger.info( + "Health check posted", + extra={ + "responseBody": response.text, + "responseText": response.headers, + }, + ) else: self.logger.warning( - "Healthcheck failed", + "Health check failed", extra={"statusCode": response.status_code}, ) + else: + self.logger.info( + "Health check skipped", + extra={"timeSinceLastHealthcheck": timeSinceLastHealthcheck}, + ) def ackRadioCheck(self, packet, interface): """Respond to a radio check""" @@ -265,7 +277,7 @@ def idToHex(self, nodeId): return "!" + hex(nodeId)[2:] -# Basd on unit test here: https://github.com/madzak/python-json-logger/blob/5f85723f4693c7289724fdcda84cfc0b62da74d4/tests/test_jsonlogger.py#L87 +# Based on unit test here: https://github.com/madzak/python-json-logger/blob/5f85723f4693c7289724fdcda84cfc0b62da74d4/tests/test_jsonlogger.py#L87 def getLogFormat(): supported_keys = [ "asctime",