From 6cd09c0f10ae9667925cb03491ee5992bd6875aa Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 8 Dec 2024 19:06:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20simpleadmin/www/index.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add system status card. --- simpleadmin/www/index.html | 99 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/simpleadmin/www/index.html b/simpleadmin/www/index.html index 7c19596..126e217 100644 --- a/simpleadmin/www/index.html +++ b/simpleadmin/www/index.html @@ -278,6 +278,76 @@
+
+
系统状态
+
+
+ + + + + + + + + + + +
CPU使用率 +
+
+ +
+
+
内存使用率 +
+
+ +
+
+
+
+
+
+
信号
@@ -649,6 +719,12 @@ nonNrUpload: "0", downloadStat: "0", uploadStat: "0", + cpuUsage: "0", + memoryUsage: "0", + cacheUsage: "0", + memoryTotal: "0", + memoryUsed: "0", + cacheUsed: "0", fetchAllInfo() { this.atcmd = @@ -1952,6 +2028,29 @@ console.log("Refreshed"); }, this.refreshRate * 1000); }, + + fetchSystemStats() { + fetch("/cgi-bin/get_system_stats") + .then(response => response.text()) + .then(data => { + const lines = data.split("\n"); + // 跳过空行和Content-Type行 + const validLines = lines.filter(line => line.trim() !== '' && line.includes(": ")).map(line => line.trim()); + + this.cpuUsage = parseFloat(validLines[0].split(": ")[1]).toFixed(1); + this.memoryUsage = parseFloat(validLines[1].split(": ")[1]).toFixed(1); + this.memoryTotal = parseInt(validLines[2].split(": ")[1]); + this.memoryUsed = parseInt(validLines[3].split(": ")[1]); + }); + }, + + formatBytes(bytes) { + if (bytes === 0) return '0 B'; + const k = 1024; + const sizes = ['B', 'KB', 'MB', 'GB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; + }, }; }