Improve status API. Closes #11

This commit is contained in:
Ian Renton
2025-09-29 21:30:50 +01:00
parent ac6d4d40cd
commit 280749919d
3 changed files with 59 additions and 19 deletions

15
main.py
View File

@@ -1,9 +1,14 @@
# Main script
import logging
import os
import signal
import sys
from datetime import datetime
from time import sleep
import psutil
import pytz
from core.cleanup import CleanupTimer
from core.config import config
from providers.aprsis import APRSIS
@@ -70,6 +75,7 @@ if __name__ == '__main__':
handler.setFormatter(formatter)
root.addHandler(handler)
logging.info("Starting...")
startup_time = datetime.now(pytz.UTC)
# Shut down gracefully on SIGINT
signal.signal(signal.SIGINT, shutdown)
@@ -94,6 +100,9 @@ if __name__ == '__main__':
# While running, update the status information at a regular interval
while run:
sleep(5)
for p in providers: status_data[p.name()] = {"status": p.status, "last_updated": p.last_update_time, "last_spot": p.last_spot_time}
status_data["Cleanup Timer"] = {"status": cleanup_timer.status, "last_ran": cleanup_timer.last_cleanup_time}
status_data["Web Server"] = {"status": web_server.status, "last_api_access": web_server.last_api_access_time, "last_page_access": web_server.last_page_access_time}
status_data["uptime"] = str(datetime.now(pytz.UTC) - startup_time).split(".")[0]
status_data["mem_use_mb"] = round(psutil.Process(os.getpid()).memory_info().rss / (1024 * 1024), 3)
status_data["num_spots"] = len(spot_list)
status_data["providers"] = list(map(lambda p: {"name": p.name(), "status": p.status, "last_updated": p.last_update_time, "last_spot": p.last_spot_time}, providers))
status_data["cleanup"] = {"status": cleanup_timer.status, "last_ran": cleanup_timer.last_cleanup_time}
status_data["webserver"] = {"status": web_server.status, "last_api_access": web_server.last_api_access_time, "last_page_access": web_server.last_page_access_time}