mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-28 01:09:26 +00:00
Improve status API. Closes #11
This commit is contained in:
15
main.py
15
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}
|
||||
|
||||
Reference in New Issue
Block a user