MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / getNodeDetails

Function getNodeDetails

komari/komari.ts:442–566  ·  view source on GitHub ↗
(
  baseUrl: string,
  nodeName: string
)

Source from the content-addressed store, hash-verified

440
441// 获取指定节点详细信息
442async function getNodeDetails(
443 baseUrl: string,
444 nodeName: string
445): Promise<string> {
446 try {
447 // 获取公开信息
448 const publicData = await makeRequest(baseUrl, "/api/public");
449
450 // 获取节点列表
451 const nodesData = await makeRequest(baseUrl, "/api/nodes");
452
453 if (publicData.status !== "success" || nodesData.status !== "success") {
454 throw new Error("API 返回状态异常");
455 }
456
457 const siteName = publicData.data.sitename || "未知站点";
458 const nodes = nodesData.data;
459
460 // 查找指定名称的节点
461 const targetNode = nodes.find((node: any) => node.name === nodeName);
462 if (!targetNode) {
463 throw new Error(`未找到名为 "${nodeName}" 的节点`);
464 }
465
466 // 获取节点实时数据
467 const recentData = await makeRequest(
468 baseUrl,
469 `/api/recent/${targetNode.uuid}`
470 );
471 if (recentData.status !== "success" || recentData.data.length === 0) {
472 throw new Error(`无法获取节点 "${nodeName}" 的实时数据,节点可能离线`);
473 }
474
475 const realtime = recentData.data[0];
476 const node = targetNode;
477
478 // 格式化数据
479 const cpuUsage = (realtime.cpu?.usage || 0).toFixed(2);
480
481 const memUsed = realtime.ram?.used || 0;
482 const memTotal = realtime.ram?.total || 0;
483 const memPercent =
484 memTotal > 0 ? ((memUsed / memTotal) * 100).toFixed(2) : "0.00";
485
486 const swapUsed = realtime.swap?.used || 0;
487 const swapTotal = realtime.swap?.total || 0;
488 const swapPercent =
489 swapTotal > 0 ? ((swapUsed / swapTotal) * 100).toFixed(2) : "0.00";
490
491 const diskUsed = realtime.disk?.used || 0;
492 const diskTotal = realtime.disk?.total || 0;
493 const diskPercent =
494 diskTotal > 0 ? ((diskUsed / diskTotal) * 100).toFixed(2) : "0.00";
495
496 const netDown = realtime.network?.totalDown || 0;
497 const netUp = realtime.network?.totalUp || 0;
498
499 const upSpeed = formatSpeed(realtime.network?.up || 0);

Callers 1

handleKomariRequestFunction · 0.85

Calls 5

makeRequestFunction · 0.85
formatExpiredDateFunction · 0.85
formatSpeedFunction · 0.70
formatUptimeFunction · 0.70
formatBytesFunction · 0.70

Tested by

no test coverage detected