diff options
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/__init__.py | 2 | ||||
-rw-r--r-- | kvmd/apps/kvmd/api/export.py | 8 | ||||
-rw-r--r-- | kvmd/htserver.py | 6 |
3 files changed, 9 insertions, 7 deletions
diff --git a/kvmd/__init__.py b/kvmd/__init__.py index 83d7646c..01e76ba6 100644 --- a/kvmd/__init__.py +++ b/kvmd/__init__.py @@ -20,4 +20,4 @@ # ========================================================================== # -__version__ = "3.234" +__version__ = "3.238" diff --git a/kvmd/apps/kvmd/api/export.py b/kvmd/apps/kvmd/api/export.py index cfcbde41..a5d4d0bf 100644 --- a/kvmd/apps/kvmd/api/export.py +++ b/kvmd/apps/kvmd/api/export.py @@ -24,6 +24,8 @@ import asyncio from typing import Any +import async_lru + from aiohttp.web import Request from aiohttp.web import Response @@ -49,6 +51,10 @@ class ExportApi: @exposed_http("GET", "/export/prometheus/metrics") async def __prometheus_metrics_handler(self, _: Request) -> Response: + return Response(text=(await self.__get_prometheus_metrics())) + + @async_lru.alru_cache(maxsize=1, ttl=5) + async def __get_prometheus_metrics(self) -> str: (atx_state, hw_state, fan_state, gpio_state) = await asyncio.gather(*[ self.__atx.get_state(), self.__info_manager.get_submanager("hw").get_state(), @@ -68,7 +74,7 @@ class ExportApi: self.__append_prometheus_rows(rows, hw_state["health"], "pikvm_hw") self.__append_prometheus_rows(rows, fan_state, "pikvm_fan") - return Response(text="\n".join(rows)) + return "\n".join(rows) def __append_prometheus_rows(self, rows: list[str], value: Any, path: str) -> None: if isinstance(value, bool): diff --git a/kvmd/htserver.py b/kvmd/htserver.py index fa2aedc4..df5a3123 100644 --- a/kvmd/htserver.py +++ b/kvmd/htserver.py @@ -41,14 +41,10 @@ from aiohttp.web import StreamResponse from aiohttp.web import WebSocketResponse from aiohttp.web import WSMsgType from aiohttp.web import Application +from aiohttp.web import AccessLogger from aiohttp.web import run_app from aiohttp.web import normalize_path_middleware -try: - from aiohttp.web import AccessLogger # type: ignore -except ImportError: - from aiohttp.helpers import AccessLogger # type: ignore - from .logging import get_logger from .errors import OperationError |