summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-09-03 12:05:41 +0300
committerDevaev Maxim <[email protected]>2020-09-03 12:05:41 +0300
commit6820c31626fbab36347979d7e636e7c9b5513801 (patch)
tree1c267fc16e5c4aafac9006eeec60127d90603973 /kvmd
parent4f3875bf51115d38657a9c836ea6e4768cd1043c (diff)
pass gpio to prometheus metrics
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/kvmd/api/export.py10
-rw-r--r--kvmd/apps/kvmd/server.py2
2 files changed, 9 insertions, 3 deletions
diff --git a/kvmd/apps/kvmd/api/export.py b/kvmd/apps/kvmd/api/export.py
index c37feb57..6dae0ce1 100644
--- a/kvmd/apps/kvmd/api/export.py
+++ b/kvmd/apps/kvmd/api/export.py
@@ -32,27 +32,33 @@ from aiohttp.web import Response
from ....plugins.atx import BaseAtx
from ..info import InfoManager
+from ..ugpio import UserGpio
from ..http import exposed_http
# =====
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.__atx = atx
+ self.__user_gpio = user_gpio
# =====
@exposed_http("GET", "/export/prometheus/metrics")
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.__info_manager.get_submanager("hw").get_state(),
+ self.__user_gpio.get_state(),
])
rows: List[str] = []
self.__append_prometheus_rows(rows, atx_state["enabled"], "pikvm_atx_enabled")
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:
self.__append_prometheus_rows(rows, hw_state["health"], "pikvm_hw")
return Response(text="\n".join(rows))
diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py
index 3f1361aa..ac7552a8 100644
--- a/kvmd/apps/kvmd/server.py
+++ b/kvmd/apps/kvmd/server.py
@@ -191,7 +191,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
AtxApi(atx),
MsdApi(msd, sync_chunk_size),
StreamerApi(streamer),
- ExportApi(info_manager, atx),
+ ExportApi(info_manager, atx, user_gpio),
]
self.__ws_handlers: Dict[str, Callable] = {}