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

Function getServerInfo

komari/komari.ts:243–294  ·  view source on GitHub ↗
(baseUrl: string)

Source from the content-addressed store, hash-verified

241
242// 获取服务器基本信息
243async function getServerInfo(baseUrl: string): Promise<string> {
244 try {
245 // 获取公开信息
246 const publicData = await makeRequest(baseUrl, "/api/public");
247
248 // 获取版本信息
249 const versionData = await makeRequest(baseUrl, "/api/version");
250
251 // 获取节点列表
252 const nodesData = await makeRequest(baseUrl, "/api/nodes");
253
254 if (
255 publicData.status !== "success" ||
256 versionData.status !== "success" ||
257 nodesData.status !== "success"
258 ) {
259 throw new Error("API 返回状态异常");
260 }
261
262 const siteName = publicData.data.sitename || "未知站点";
263 const version = `${versionData.data.version}-${versionData.data.hash}`;
264 const nodes = nodesData.data;
265
266 // 计算总资源
267 let totalCores = 0;
268 let totalMemory = 0;
269 let totalSwap = 0;
270 let totalDisk = 0;
271
272 nodes.forEach((node: any) => {
273 totalCores += node.cpu_cores || 0;
274 totalMemory += node.mem_total || 0;
275 totalSwap += node.swap_total || 0;
276 totalDisk += node.disk_total || 0;
277 });
278
279 return `🎯 **Komari 服务信息**
280
281**📊 基本信息**
282• **站点名称**: \`${siteName}\`
283• **Komari 版本**: \`${version}\`
284• **节点数量**: \`${nodes.length}\`
285
286**💾 资源统计**
287• **CPU 核心总数**: \`${totalCores}\`
288• **内存总量**: \`${formatBytes(totalMemory)}\`
289• **交换分区总量**: \`${formatBytes(totalSwap)}\`
290• **硬盘总量**: \`${formatBytes(totalDisk)}\``;
291 } catch (error: any) {
292 throw new Error(`获取服务器信息失败: ${error.message}`);
293 }
294}
295
296// 获取节点总览信息
297async function getNodesOverview(baseUrl: string): Promise<string> {

Callers 1

handleKomariRequestFunction · 0.85

Calls 2

makeRequestFunction · 0.85
formatBytesFunction · 0.70

Tested by

no test coverage detected