diff --git a/main.py b/main.py index e95ab98..903f6b2 100644 --- a/main.py +++ b/main.py @@ -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} diff --git a/requirements.txt b/requirements.txt index d2f6cf7..41a362a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ telnetlib3~=2.0.8 pytz~=2025.2 requests~=2.32.5 aprslib~=0.7.2 -diskcache~=5.6.3 \ No newline at end of file +diskcache~=5.6.3 +psutil~=7.1.0 \ No newline at end of file diff --git a/webassets/apidocs/openapi.yml b/webassets/apidocs/openapi.yml index 97994a1..46bf756 100644 --- a/webassets/apidocs/openapi.yml +++ b/webassets/apidocs/openapi.yml @@ -184,39 +184,49 @@ paths: schema: type: object properties: - "Web Server": + "uptime": + type: string + description: The amount of time the software has been running for. + example: "12:34:56" + "mem_use_mb": + type: number + description: The amount of memory the software is using, in megabytes. + example: 123.456 + "num_spots": + type: integer + description: Number of spots currently in the system. + example: 123 + "cleanup": type: object properties: status: type: string + description: The status of the cleanup thread example: OK last_ran: type: string + description: The last time the cleanup operation ran example: 2025-09-28T20:31:00+00:00 - "Cleanup Timer": + "webserver": type: object properties: status: type: string + description: The status of the web server example: OK last_page_access: type: string + description: The last time a page was accessed on the web server example: 2025-09-28T20:31:00+00:00 last_api_access: type: string + description: The last time an API endpoint was accessed on the web server example: 2025-09-28T20:31:00+00:00 - "POTA...": - type: object - properties: - status: - type: string - example: OK - last_updated: - type: string - example: 2025-09-28T20:31:00+00:00 - last_spot: - type: string - example: 2025-09-28T20:31:00+00:00 + providers: + type: array + description: An array of all the data providers. + items: + $ref: '#/components/schemas/ProviderStatus' components: schemas: @@ -448,4 +458,24 @@ components: source_id: type: string description: The ID the source gave it, if any. - example: "GUID-123456" \ No newline at end of file + example: "GUID-123456" + + ProviderStatus: + type: object + properties: + name: + type: string + description: The name of the provider. + example: POTA + status: + type: string + description: The status of the provider. + example: OK + last_updated: + type: string + description: The last time at which this provider received data. + example: 2025-09-28T20:31:00+00:00 + last_spot: + type: string + description: The time of the latest spot received by this provider. + example: 2025-09-28T20:31:00+00:00 \ No newline at end of file