Fix Console language support and named frame monitoring cards

This commit is contained in:
way
2026-10-17 23:07:49 +08:00
parent d2498ba68b
commit f45eefa31b
8 changed files with 116 additions and 8 deletions
+29 -2
View File
@@ -16,6 +16,15 @@ OUTPUT_LOCK = threading.Lock()
DEVICE_LOCKS = {}
LOCK = threading.Lock()
MAX_MESSAGE = 16 * 1024 * 1024
METRIC_LABELS = {
"service_ready": {"zh": "服务就绪", "en": "Service ready"},
"device_online": {"zh": "画框在线", "en": "Frame online"},
"battery_percent": {"zh": "电量", "en": "Battery"},
"job_enabled": {"zh": "任务启用", "en": "Job enabled"},
"last_run_success": {"zh": "最近运行成功", "en": "Last run succeeded"},
"device_count": {"zh": "画框数量", "en": "Frame count"},
"job_count": {"zh": "任务数量", "en": "Job count"},
}
class AdapterError(Exception):
@@ -89,10 +98,28 @@ def collect(device):
alerts = []
def metric(rid, key, value, unit="boolean"):
metrics.append({"resource_id": rid, "key": key, "value": value, "unit": unit})
metrics.append(
{
"resource_id": rid,
"key": key,
"value": value,
"unit": unit,
"label": METRIC_LABELS[key],
}
)
def alert(identifier):
alerts.append({"id": identifier, "severity": 1})
kind = identifier.split(":", 1)[0]
labels = {
"SERVICE_NOT_READY": {"zh": "服务未就绪", "en": "Service not ready"},
"DEVICE_OFFLINE": {"zh": "画框离线", "en": "Frame offline"},
"JOB_FAILED": {"zh": "任务最近运行失败", "en": "Last job run failed"},
"JOB_UNKNOWN": {
"zh": "任务最近结果待确认",
"en": "Last job result unconfirmed",
},
}
alerts.append({"id": identifier, "severity": 1, "label": labels[kind]})
metric("service", "service_ready", int(ready["status"] == "ready"))
if ready["status"] != "ready":