From 15471849036374daf22d7212b29146d2951272f9 Mon Sep 17 00:00:00 2001 From: xxxizum1kxxx <244161265+xxxizum1kxxx@users.noreply.github.com> Date: Sun, 30 Nov 2025 13:47:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20disk.Partitions=E6=94=B9=E4=B8=BAfalse?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E6=9C=AA=E7=9F=A5=E5=88=86=E5=8C=BA=20/=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0zfs=E5=8E=BB=E9=87=8D=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E8=AE=A1=E7=AE=97=E7=A3=81=E7=9B=98=E7=A9=BA?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monitoring/unit/disk.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/monitoring/unit/disk.go b/monitoring/unit/disk.go index f164859..ee171fa 100644 --- a/monitoring/unit/disk.go +++ b/monitoring/unit/disk.go @@ -14,7 +14,7 @@ type DiskInfo struct { func Disk() DiskInfo { diskinfo := DiskInfo{} - usage, err := disk.Partitions(true) + usage, err := disk.Partitions(false) if err != nil { diskinfo.Total = 0 diskinfo.Used = 0 @@ -36,17 +36,39 @@ func Disk() DiskInfo { } } else { // 使用默认逻辑,排除临时文件系统和网络驱动器 + deviceMap := make(map[string]*disk.UsageStat) + for _, part := range usage { if isPhysicalDisk(part) { u, err := disk.Usage(part.Mountpoint) if err != nil { continue + } + + deviceID := part.Device + // ZFS去重: 基于 pool 名称 (例如 pool/dataset -> pool) + if strings.ToLower(part.Fstype) == "zfs" { + if idx := strings.Index(deviceID, "/"); idx != -1 { + deviceID = deviceID[:idx] + } + } + + // 如果该设备已存在,且当前挂载点的 Total 更大,则替换(处理 quota 等情况) + // 否则保留现有的(通常我们希望统计物理 pool 的总量) + if existing, ok := deviceMap[deviceID]; ok { + if u.Total > existing.Total { + deviceMap[deviceID] = u + } } else { - diskinfo.Total += u.Total - diskinfo.Used += u.Used + deviceMap[deviceID] = u } } } + + for _, u := range deviceMap { + diskinfo.Total += u.Total + diskinfo.Used += u.Used + } } } return diskinfo