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 # Main script
import logging import logging
import os
import signal import signal
import sys import sys
from datetime import datetime
from time import sleep from time import sleep
import psutil
import pytz
from core.cleanup import CleanupTimer from core.cleanup import CleanupTimer
from core.config import config from core.config import config
from providers.aprsis import APRSIS from providers.aprsis import APRSIS
@@ -70,6 +75,7 @@ if __name__ == '__main__':
handler.setFormatter(formatter) handler.setFormatter(formatter)
root.addHandler(handler) root.addHandler(handler)
logging.info("Starting...") logging.info("Starting...")
startup_time = datetime.now(pytz.UTC)
# Shut down gracefully on SIGINT # Shut down gracefully on SIGINT
signal.signal(signal.SIGINT, shutdown) signal.signal(signal.SIGINT, shutdown)
@@ -94,6 +100,9 @@ if __name__ == '__main__':
# While running, update the status information at a regular interval # While running, update the status information at a regular interval
while run: while run:
sleep(5) 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["uptime"] = str(datetime.now(pytz.UTC) - startup_time).split(".")[0]
status_data["Cleanup Timer"] = {"status": cleanup_timer.status, "last_ran": cleanup_timer.last_cleanup_time} status_data["mem_use_mb"] = round(psutil.Process(os.getpid()).memory_info().rss / (1024 * 1024), 3)
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["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}

View File

@@ -7,3 +7,4 @@ pytz~=2025.2
requests~=2.32.5 requests~=2.32.5
aprslib~=0.7.2 aprslib~=0.7.2
diskcache~=5.6.3 diskcache~=5.6.3
psutil~=7.1.0

View File

@@ -184,39 +184,49 @@ paths:
schema: schema:
type: object type: object
properties: 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 type: object
properties: properties:
status: status:
type: string type: string
description: The status of the cleanup thread
example: OK example: OK
last_ran: last_ran:
type: string type: string
description: The last time the cleanup operation ran
example: 2025-09-28T20:31:00+00:00 example: 2025-09-28T20:31:00+00:00
"Cleanup Timer": "webserver":
type: object type: object
properties: properties:
status: status:
type: string type: string
description: The status of the web server
example: OK example: OK
last_page_access: last_page_access:
type: string type: string
description: The last time a page was accessed on the web server
example: 2025-09-28T20:31:00+00:00 example: 2025-09-28T20:31:00+00:00
last_api_access: last_api_access:
type: string type: string
description: The last time an API endpoint was accessed on the web server
example: 2025-09-28T20:31:00+00:00 example: 2025-09-28T20:31:00+00:00
"POTA...": providers:
type: object type: array
properties: description: An array of all the data providers.
status: items:
type: string $ref: '#/components/schemas/ProviderStatus'
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
components: components:
schemas: schemas:
@@ -449,3 +459,23 @@ components:
type: string type: string
description: The ID the source gave it, if any. description: The ID the source gave it, if any.
example: "GUID-123456" 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