diff --git a/core/status_reporter.py b/core/status_reporter.py index 74ae112..609f938 100644 --- a/core/status_reporter.py +++ b/core/status_reporter.py @@ -11,6 +11,7 @@ from core.constants import SOFTWARE_VERSION from core.data_providers import DATA_PROVIDERS from core.data_store import DATA_STORE from core.prometheus_metrics_handler import alerts_gauge, memory_use_gauge, spots_gauge +from telnetserver.telnetserver import TELNET_SERVER from webserver.webserver import WEB_SERVER @@ -134,19 +135,13 @@ class StatusReporter: else 0, } DATA_STORE.status.get()["webserver"] = { - "status": WEB_SERVER.web_server_metrics["status"], - "last_api_access": WEB_SERVER.web_server_metrics["last_api_access_time"] - .replace(tzinfo=pytz.UTC) - .timestamp() - if WEB_SERVER.web_server_metrics["last_api_access_time"] - else 0, - "api_access_count": WEB_SERVER.web_server_metrics["api_access_counter"], - "last_page_access": WEB_SERVER.web_server_metrics["last_page_access_time"] - .replace(tzinfo=pytz.UTC) - .timestamp() - if WEB_SERVER.web_server_metrics["last_page_access_time"] - else 0, - "page_access_count": WEB_SERVER.web_server_metrics["page_access_counter"], + "status": WEB_SERVER.web_server_metrics.status, + "api_requests_per_hour": WEB_SERVER.web_server_metrics.api_requests_per_hour(), + "page_requests_per_hour": WEB_SERVER.web_server_metrics.page_requests_per_hour(), + "sse_client_count": WEB_SERVER.sse_client_count, + } + DATA_STORE.status.get()["telnet"] = { + "client_count": TELNET_SERVER.client_count, } DATA_STORE.status.store() diff --git a/static/apidocs/openapi.yml b/static/apidocs/openapi.yml index 55fccf8..81f8661 100644 --- a/static/apidocs/openapi.yml +++ b/static/apidocs/openapi.yml @@ -25,7 +25,9 @@ info: * Added `contests_skip_max_duration_check` to alert query parameters * SIG reference types (e.g. "Park") are now capitalised to match other enums * Added the ability to get only certain fields of spots and alerts from the API by using the `fields` query parameter. - + * Replace `last_page_access` with `page_requests_per_hour` and `last_api_access` with `api_requests_per_hour` in the web server stats. + * Added `sse_client_count` to the `webserver` stats, and a new `telnet` object with `client_count`. + ### 2.0 * **Breaking change:** The "add spot" API has changed to enable future support for upstream submission to the spotting services associated with various SIGs. Instead of just posting the spot object itself as the JSON content of the POST, this has moved into a `spot` object within the structure. A new `handling` object alongside it contains the `submit_upstream`, `upstream_provider`, `upstream_credentials`, and `captcha_token` fields which control the server handling of the spot. @@ -2100,14 +2102,25 @@ components: type: string description: The status of the web server example: OK - last_page_access: - type: number - description: The last time a page was accessed on the web server, UTC seconds since UNIX epoch. - example: 1759579508 - last_api_access: - type: number - description: The last time an API endpoint was accessed on the web server, UTC seconds since UNIX epoch. - example: 1759579508 + page_requests_per_hour: + type: integer + description: The number of page requests handled by the web server in the last hour + example: 123 + api_requests_per_hour: + type: integer + description: The number of API requests handled by the web server in the last hour + example: 123 + sse_client_count: + type: integer + description: The number of clients currently connected to SSE streams + example: 5 + "telnet": + type: object + properties: + client_count: + type: integer + description: The number of clients currently connected to the telnet server + example: 2 spot_providers: type: array description: An array of all the spot providers. diff --git a/static/js/status.js b/static/js/status.js index e42dd2e..cb1c731 100644 --- a/static/js/status.js +++ b/static/js/status.js @@ -9,8 +9,10 @@ function loadStatus() { $("#total-alerts").text(jsonData["num_alerts"]); $("#web-server-status").text(jsonData["webserver"]["status"]); - $("#web-server-last-api").text(moment.unix(jsonData["webserver"]["last_api_access"]).utc().fromNow()); - $("#web-server-last-page").text(moment.unix(jsonData["webserver"]["last_page_access"]).utc().fromNow()); + $("#web-server-api-rate").text(jsonData["webserver"]["api_requests_per_hour"] + " / hour"); + $("#web-server-page-rate").text(jsonData["webserver"]["page_requests_per_hour"] + " / hour"); + $("#web-server-sse-clients").text(jsonData["webserver"]["sse_client_count"]); + $("#telnet-server-clients").text(jsonData["telnet"]["client_count"]); $("#cleanup-status").text(jsonData["cleanup"]["status"]); $("#cleanup-last-ran").text((jsonData["cleanup"]["last_ran"] > 0) ? moment.unix(jsonData["cleanup"]["last_ran"]).utc().fromNow() : "N/A"); diff --git a/telnetserver/telnetserver.py b/telnetserver/telnetserver.py index 993d248..2f19d20 100644 --- a/telnetserver/telnetserver.py +++ b/telnetserver/telnetserver.py @@ -101,6 +101,10 @@ class TelnetServer: logger.debug("Stopping telnet server...") self._loop.call_soon_threadsafe(self._shutdown_event.set) + @property + def client_count(self) -> int: + return len(self._clients) + async def _stop_internal(self): """Stops the telnet server""" diff --git a/templates/add_spot.html b/templates/add_spot.html index d0bd641..583505b 100644 --- a/templates/add_spot.html +++ b/templates/add_spot.html @@ -77,7 +77,7 @@ - + diff --git a/templates/alerts.html b/templates/alerts.html index 1aef369..7a18ae8 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -83,7 +83,7 @@ - + diff --git a/templates/bands.html b/templates/bands.html index 9ed712e..7737dc8 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -76,8 +76,8 @@ - - + + diff --git a/templates/base.html b/templates/base.html index fe101b5..da7a6e6 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,6 @@ {% extends "skeleton.html" %} {% block head_extra %} - + @@ -16,10 +16,10 @@ window.fetchEventSource = fetchEventSource; - - - - + + + + {% end %} {% block body %}