From c66d754c77c045fad092ff34027a59b462d3ef65 Mon Sep 17 00:00:00 2001 From: gaoxq <376340421@qq.com> Date: Mon, 13 Apr 2026 18:22:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=8E=A5=E5=8F=A3=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jeesite/modules/utils/DockerUtil.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/web-api/src/main/java/com/jeesite/modules/utils/DockerUtil.java b/web-api/src/main/java/com/jeesite/modules/utils/DockerUtil.java index 316b7f9..5c9df61 100644 --- a/web-api/src/main/java/com/jeesite/modules/utils/DockerUtil.java +++ b/web-api/src/main/java/com/jeesite/modules/utils/DockerUtil.java @@ -119,4 +119,37 @@ public class DockerUtil { String res = runCommand(accounts, "docker inspect " + containerId); return res != null ? DockerResult.ok(res) : DockerResult.fail("查询详情失败"); } + + /** + * 获取CPU使用率 + */ + public static String getCpuUsage(MySftpAccounts accounts) { + try { + return runCommand(accounts, "top -bn1 | grep Cpu | awk '{print 100 - $8}'"); + } catch (Exception e) { + return null; + } + } + + /** + * 获取内存使用情况 + */ + public static String getMemoryUsage(MySftpAccounts accounts) { + try { + return runCommand(accounts, "free -m | grep Mem | awk '{print $3\"MB / \"$2\"MB\"}'"); + } catch (Exception e) { + return null; + } + } + + /** + * 获取磁盘使用情况 + */ + public static String getDiskUsage(MySftpAccounts accounts) { + try { + return runCommand(accounts, "df -h / | grep / | awk '{print $3\" / \"$2}\" \"$5}'"); + } catch (Exception e) { + return null; + } + } } \ No newline at end of file