过滤资源监控中的虚拟磁盘挂载点
This commit is contained in:
@@ -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": {
|
||||
|
||||
@@ -281,7 +281,9 @@
|
||||
<div slot="header" class="workspace-header">
|
||||
<div>
|
||||
<h3>磁盘挂载点</h3>
|
||||
<p>按使用率排序展示常用挂载点,方便快速发现哪个分区快满了。</p>
|
||||
<p>
|
||||
{% raw %}{{ diskMountBrief }}{% endraw %}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<el-table :data="disk.items || []" size="mini" style="width: 100%">
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user