feat: Sentinel节点卡片添加HTTP链路延迟显示(横版左下角/网格右上角)
This commit is contained in:
@@ -116,6 +116,7 @@ class Plugin(PluginWebMixin):
|
||||
"system": c.get("system", {}),
|
||||
"platform": c.get("platform", {}),
|
||||
"last_seen": c.get("last_seen", 0),
|
||||
"latency_ms": c.get("latency_ms", 0),
|
||||
"error": c.get("error", ""),
|
||||
})
|
||||
return web.json_response({"nodes": result})
|
||||
@@ -195,12 +196,13 @@ class Plugin(PluginWebMixin):
|
||||
for node in nodes:
|
||||
if not node.get("enabled", True):
|
||||
continue
|
||||
online, sys_info, err = await self._fetch_system(node)
|
||||
online, sys_info, err, latency = await self._fetch_system(node)
|
||||
_NODE_CACHE[node.get("id", "")] = {
|
||||
"online": online,
|
||||
"system": sys_info or {},
|
||||
"platform": (sys_info or {}).get("platform", {}),
|
||||
"last_seen": time.time(),
|
||||
"latency_ms": latency,
|
||||
"error": err if not online else "",
|
||||
}
|
||||
# 每次轮询都推送 SSE (确保实时性)
|
||||
@@ -217,14 +219,17 @@ class Plugin(PluginWebMixin):
|
||||
|
||||
def _sync_fetch():
|
||||
try:
|
||||
t0 = time.time()
|
||||
headers = {"Authorization": f"Bearer {api_key}"} if api_key else {}
|
||||
req = urllib.request.Request(f"{url}{base}/api/system", headers=headers)
|
||||
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||||
elapsed = round((time.time() - t0) * 1000) # ms
|
||||
if resp.status == 200:
|
||||
return True, _json.loads(resp.read().decode()), ""
|
||||
return False, None, f"HTTP {resp.status}"
|
||||
return True, _json.loads(resp.read().decode()), "", elapsed
|
||||
return False, None, f"HTTP {resp.status}", elapsed
|
||||
except Exception as e:
|
||||
return False, None, str(e)[:120]
|
||||
elapsed = round((time.time() - t0) * 1000)
|
||||
return False, None, str(e)[:120], elapsed
|
||||
|
||||
return await asyncio.get_event_loop().run_in_executor(None, _sync_fetch)
|
||||
|
||||
@@ -242,6 +247,7 @@ class Plugin(PluginWebMixin):
|
||||
"system": c.get("system", {}),
|
||||
"platform": c.get("platform", {}),
|
||||
"last_seen": c.get("last_seen", 0),
|
||||
"latency_ms": c.get("latency_ms", 0),
|
||||
"error": c.get("error", ""),
|
||||
})
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user