Fix Console language support and named frame monitoring cards
This commit is contained in:
+29
-2
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user