summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-04-25 15:44:00 +0300
committerMaxim Devaev <[email protected]>2022-04-25 15:44:00 +0300
commit293490298cbe5896920b338f05a8d269b47c04fd (patch)
tree539cc1b49251f0c9b3ca51c0939be8c5bbacc312
parent2294b5a9e167d72eecfd527c2f296312c34fbf2c (diff)
report a serial number
-rw-r--r--kvmd/apps/kvmd/info/hw.py25
-rw-r--r--testenv/fakes/proc/device-tree/serial-number1
-rw-r--r--web/share/js/kvm/session.js7
3 files changed, 23 insertions, 10 deletions
diff --git a/kvmd/apps/kvmd/info/hw.py b/kvmd/apps/kvmd/info/hw.py
index 9a4d0c53..aac21c15 100644
--- a/kvmd/apps/kvmd/info/hw.py
+++ b/kvmd/apps/kvmd/info/hw.py
@@ -20,6 +20,7 @@
# ========================================================================== #
+import os
import asyncio
from typing import List
@@ -53,9 +54,12 @@ class HwInfoSubmanager(BaseInfoSubmanager):
self.__vcgencmd_cmd = vcgencmd_cmd
self.__state_poll = state_poll
+ self.__dt_cache: Dict[str, str] = {}
+
async def get_state(self) -> Dict:
- (model, cpu_temp, throttling) = await asyncio.gather(
- self.__get_dt_model(),
+ (model, serial, cpu_temp, throttling) = await asyncio.gather(
+ self.__read_dt_file("model"),
+ self.__read_dt_file("serial-number"),
self.__get_cpu_temp(),
self.__get_throttling(),
)
@@ -63,6 +67,7 @@ class HwInfoSubmanager(BaseInfoSubmanager):
"platform": {
"type": "rpi",
"base": model,
+ "serial": serial,
},
"health": {
"temp": {
@@ -83,13 +88,15 @@ class HwInfoSubmanager(BaseInfoSubmanager):
# =====
- async def __get_dt_model(self) -> Optional[str]:
- model_path = f"{env.PROCFS_PREFIX}/proc/device-tree/model"
- try:
- return (await aiofs.read(model_path)).strip(" \t\r\n\0")
- except Exception as err:
- get_logger(0).error("Can't read DT model from %s: %s", model_path, err)
- return None
+ async def __read_dt_file(self, name: str) -> Optional[str]:
+ if name not in self.__dt_cache:
+ path = os.path.join(f"{env.PROCFS_PREFIX}/proc/device-tree", name)
+ try:
+ self.__dt_cache[name] = (await aiofs.read(path)).strip(" \t\r\n\0")
+ except Exception as err:
+ get_logger(0).error("Can't read DT %s from %s: %s", name, path, err)
+ return None
+ return self.__dt_cache[name]
async def __get_cpu_temp(self) -> Optional[float]:
temp_path = f"{env.SYSFS_PREFIX}/sys/class/thermal/thermal_zone0/temp"
diff --git a/testenv/fakes/proc/device-tree/serial-number b/testenv/fakes/proc/device-tree/serial-number
new file mode 100644
index 00000000..baa82f2a
--- /dev/null
+++ b/testenv/fakes/proc/device-tree/serial-number
@@ -0,0 +1 @@
+0000000000000000
diff --git a/web/share/js/kvm/session.js b/web/share/js/kvm/session.js
index 72d75ab6..ebcdd25d 100644
--- a/web/share/js/kvm/session.js
+++ b/web/share/js/kvm/session.js
@@ -130,7 +130,8 @@ export function Session() {
let html = "";
if (__info_hw_state !== null) {
html += `
- Platform base: <span class="code-comment">${__info_hw_state.platform.base}</span><br>
+ Platform:
+ ${__formatPlatform(__info_hw_state.platform)}
<hr>
Temperature:
${__formatTemp(__info_hw_state.health.temp)}
@@ -151,6 +152,10 @@ export function Session() {
$("about-hardware").innerHTML = html;
};
+ var __formatPlatform = function(state) {
+ return __formatUl([["Base", state.base], ["Serial", state.serial]]);
+ };
+
var __formatFan = function(state) {
if (!state.monitored) {
return __formatUl([["Status", "Not monitored"]]);