mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 01:30:31 +08:00
pass gpio to prometheus metrics
This commit is contained in:
parent
4f3875bf51
commit
6820c31626
@ -32,27 +32,33 @@ from aiohttp.web import Response
|
|||||||
from ....plugins.atx import BaseAtx
|
from ....plugins.atx import BaseAtx
|
||||||
|
|
||||||
from ..info import InfoManager
|
from ..info import InfoManager
|
||||||
|
from ..ugpio import UserGpio
|
||||||
|
|
||||||
from ..http import exposed_http
|
from ..http import exposed_http
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
class ExportApi:
|
class ExportApi:
|
||||||
def __init__(self, info_manager: InfoManager, atx: BaseAtx) -> None:
|
def __init__(self, info_manager: InfoManager, atx: BaseAtx, user_gpio: UserGpio) -> None:
|
||||||
self.__info_manager = info_manager
|
self.__info_manager = info_manager
|
||||||
self.__atx = atx
|
self.__atx = atx
|
||||||
|
self.__user_gpio = user_gpio
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|
||||||
@exposed_http("GET", "/export/prometheus/metrics")
|
@exposed_http("GET", "/export/prometheus/metrics")
|
||||||
async def __prometheus_metrics_handler(self, _: Request) -> Response:
|
async def __prometheus_metrics_handler(self, _: Request) -> Response:
|
||||||
(atx_state, hw_state) = await asyncio.gather(*[
|
(atx_state, hw_state, gpio_state) = await asyncio.gather(*[
|
||||||
self.__atx.get_state(),
|
self.__atx.get_state(),
|
||||||
self.__info_manager.get_submanager("hw").get_state(),
|
self.__info_manager.get_submanager("hw").get_state(),
|
||||||
|
self.__user_gpio.get_state(),
|
||||||
])
|
])
|
||||||
rows: List[str] = []
|
rows: List[str] = []
|
||||||
self.__append_prometheus_rows(rows, atx_state["enabled"], "pikvm_atx_enabled")
|
self.__append_prometheus_rows(rows, atx_state["enabled"], "pikvm_atx_enabled")
|
||||||
self.__append_prometheus_rows(rows, atx_state["leds"]["power"], "pikvm_atx_power")
|
self.__append_prometheus_rows(rows, atx_state["leds"]["power"], "pikvm_atx_power")
|
||||||
|
for mode in ["input", "output"]:
|
||||||
|
for (channel, gch) in gpio_state[f"{mode}s"].items():
|
||||||
|
self.__append_prometheus_rows(rows, gch["state"], f"pikvm_gpio_input_{channel}")
|
||||||
if hw_state is not None:
|
if hw_state is not None:
|
||||||
self.__append_prometheus_rows(rows, hw_state["health"], "pikvm_hw")
|
self.__append_prometheus_rows(rows, hw_state["health"], "pikvm_hw")
|
||||||
return Response(text="\n".join(rows))
|
return Response(text="\n".join(rows))
|
||||||
|
|||||||
@ -191,7 +191,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
|
|||||||
AtxApi(atx),
|
AtxApi(atx),
|
||||||
MsdApi(msd, sync_chunk_size),
|
MsdApi(msd, sync_chunk_size),
|
||||||
StreamerApi(streamer),
|
StreamerApi(streamer),
|
||||||
ExportApi(info_manager, atx),
|
ExportApi(info_manager, atx, user_gpio),
|
||||||
]
|
]
|
||||||
|
|
||||||
self.__ws_handlers: Dict[str, Callable] = {}
|
self.__ws_handlers: Dict[str, Callable] = {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user