From df4817e099cfa6fa06ea907046b73111a3c0413d Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 6 May 2026 10:49:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=87=E6=BB=A4=E8=B5=84=E6=BA=90=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E4=B8=AD=E7=9A=84=E8=99=9A=E6=8B=9F=E7=A3=81=E7=9B=98?= =?UTF-8?q?=E6=8C=82=E8=BD=BD=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/dashboard/blueprints/system.py | 60 ++++++++++++++++++++ admin/dashboard/templates/system_status.html | 11 +++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/admin/dashboard/blueprints/system.py b/admin/dashboard/blueprints/system.py index 21e0efe..a660cb2 100644 --- a/admin/dashboard/blueprints/system.py +++ b/admin/dashboard/blueprints/system.py @@ -35,6 +35,42 @@ NETWORK_IO_SAMPLE = { "bytes_recv": 0, } +# 资源监控页默认隐藏这类“对日常容量判断帮助不大”的系统挂载: +# 1. `squashfs` 基本就是 Ubuntu / Snap 挂出来的只读镜像; +# 2. `/dev/loop*` 多数也是镜像回环设备,看起来 100% 但不代表真实磁盘爆满; +# 3. `/proc` / `/sys` / `/dev` 这类伪文件系统更偏内核运行态,不适合放在业务运维首页里。 +IGNORED_DISK_FSTYPES = { + "squashfs", + "proc", + "sysfs", + "devtmpfs", + "devfs", + "securityfs", + "cgroup", + "cgroup2", + "pstore", + "autofs", + "mqueue", + "hugetlbfs", + "debugfs", + "tracefs", + "configfs", + "fusectl", + "rpc_pipefs", + "tmpfs", +} +IGNORED_DISK_MOUNTPOINT_PREFIXES = ( + "/snap/", + "/proc", + "/sys", + "/dev", + "/run/", + "/var/lib/snapd/", +) +IGNORED_DISK_DEVICE_PREFIXES = ( + "/dev/loop", +) + def _system_config_path() -> str: return os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'config.yaml')) @@ -108,6 +144,25 @@ def _format_datetime_text(timestamp_value: float | int | None) -> str: return "-" +def _should_ignore_disk_partition(partition) -> bool: + """判断某个挂载点是否应该从首页磁盘列表中隐藏。""" + mountpoint = str(getattr(partition, "mountpoint", "") or "").strip() + device = str(getattr(partition, "device", "") or "").strip() + fstype = str(getattr(partition, "fstype", "") or "").strip().lower() + + # Windows 下通常不会命中这些 Linux 伪文件系统规则,这里保持跨平台兼容即可。 + if fstype in IGNORED_DISK_FSTYPES: + return True + + if any(mountpoint.startswith(prefix) for prefix in IGNORED_DISK_MOUNTPOINT_PREFIXES): + return True + + if any(device.startswith(prefix) for prefix in IGNORED_DISK_DEVICE_PREFIXES): + return True + + return False + + def _sample_network_speed() -> dict: """根据两次页面采样估算网络上下行速率。""" counters = psutil.net_io_counters() @@ -159,12 +214,16 @@ def _extract_server_runtime_snapshot() -> dict: load_values = (0.0, 0.0, 0.0) disk_items = [] + hidden_disk_items_count = 0 seen_mountpoints = set() for partition in psutil.disk_partitions(all=False): mountpoint = str(getattr(partition, "mountpoint", "") or "").strip() if not mountpoint or mountpoint in seen_mountpoints: continue seen_mountpoints.add(mountpoint) + if _should_ignore_disk_partition(partition): + hidden_disk_items_count += 1 + continue try: usage = psutil.disk_usage(mountpoint) except Exception: @@ -228,6 +287,7 @@ def _extract_server_runtime_snapshot() -> dict: "primary_used_bytes": _safe_int(getattr(primary_disk_usage, "used", 0)), "io_read_bytes": _safe_int(getattr(disk_io, "read_bytes", 0)) if disk_io else 0, "io_write_bytes": _safe_int(getattr(disk_io, "write_bytes", 0)) if disk_io else 0, + "hidden_virtual_mount_count": hidden_disk_items_count, "items": disk_items[:8], }, "network": { diff --git a/admin/dashboard/templates/system_status.html b/admin/dashboard/templates/system_status.html index 79f8210..82443f2 100644 --- a/admin/dashboard/templates/system_status.html +++ b/admin/dashboard/templates/system_status.html @@ -281,7 +281,9 @@

磁盘挂载点

-

按使用率排序展示常用挂载点,方便快速发现哪个分区快满了。

+

+ {% raw %}{{ diskMountBrief }}{% endraw %} +

@@ -403,6 +405,13 @@ const sourceText = browser.launch_source ? `source=${browser.launch_source}` : 'source=-'; return `${loopText} · ${pidText} · ${sourceText}`; }, + diskMountBrief() { + const hiddenCount = Number(this.disk.hidden_virtual_mount_count || 0); + if (hiddenCount > 0) { + return `按使用率排序展示常用挂载点,已隐藏 ${hiddenCount} 个 snap / loop / squashfs 等虚拟挂载。`; + } + return '按使用率排序展示常用挂载点,方便快速发现哪个分区快满了。'; + }, alertItems() { const items = []; const cpuUsage = this.normalizePercent(this.cpu.usage_percent);