Skip to content

Commit

Permalink
Extra logging around healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
dpup committed Nov 22, 2024
1 parent 58a1202 commit fc692d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"cSpell.words": [
"healthcheck",
"healthchecks",
"HEALTHCHECKURL",
"jsonlogger",
"levelname",
"Meshtastic",
"NODEINFO",
"portnum",
"portnums",
"pythonjsonlogger",
"radiocheck",
"rssi"
]
}
20 changes: 16 additions & 4 deletions check-mate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit fc692d5

Please sign in to comment.