Add prometheus metrics endpoint. Closes #67

This commit is contained in:
Ian Renton
2025-10-30 13:32:10 +00:00
parent a9003162cc
commit 9768f976c5
4 changed files with 67 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ import pytz
from core.config import SERVER_OWNER_CALLSIGN
from core.constants import SOFTWARE_VERSION
from core.prometheus_metrics_handler import memory_use_gauge, spots_gauge, alerts_gauge
# Provides a timed update of the application's status data.
@@ -60,8 +61,15 @@ class StatusReporter:
self.status_data["webserver"] = {"status": self.web_server.status,
"last_api_access": self.web_server.last_api_access_time.replace(
tzinfo=pytz.UTC).timestamp() if self.web_server.last_api_access_time else 0,
"api_access_count": self.web_server.api_access_counter,
"last_page_access": self.web_server.last_page_access_time.replace(
tzinfo=pytz.UTC).timestamp() if self.web_server.last_page_access_time else 0}
tzinfo=pytz.UTC).timestamp() if self.web_server.last_page_access_time else 0,
"page_access_count": self.web_server.page_access_counter}
# Update Prometheus metrics
memory_use_gauge.set(psutil.Process(os.getpid()).memory_info().rss * 1024)
spots_gauge.set(len(self.spots))
alerts_gauge.set(len(self.alerts))
self.run_timer = Timer(self.run_interval, self.run)
self.run_timer.start()