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 1/4] =?UTF-8?q?fix:=20disk.Partitions=E6=94=B9=E4=B8=BAfal?= =?UTF-8?q?se=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 From 9eb31277b7f115b623c39a3f1d6897da1d0f9dfd Mon Sep 17 00:00:00 2001 From: xxxizum1kxxx <244161265+xxxizum1kxxx@users.noreply.github.com> Date: Tue, 2 Dec 2025 19:09:54 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E6=A0=B9=E6=8D=AE=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BD=BF=E7=94=A8true=EF=BC=8C=E9=98=B2=E6=AD=A2=E7=89=A9?= =?UTF-8?q?=E7=90=86=E7=A1=AC=E7=9B=98=E8=A2=ABgopsutil=E6=84=8F=E5=A4=96?= =?UTF-8?q?=E6=8E=92=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monitoring/unit/disk.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitoring/unit/disk.go b/monitoring/unit/disk.go index ad2bd01..887eac7 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(false) + usage, err := disk.Partitions(true) if err != nil { diskinfo.Total = 0 diskinfo.Used = 0 From a4fc402efa20db7724052a9d22d9fbdc129bbf52 Mon Sep 17 00:00:00 2001 From: xxxizum1kxxx <244161265+xxxizum1kxxx@users.noreply.github.com> Date: Tue, 2 Dec 2025 19:52:26 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E6=8E=92=E9=99=A4=20Linux=20autofs?= =?UTF-8?q?=20=E4=BD=9C=E4=B8=BA=E7=89=A9=E7=90=86=E7=A3=81=E7=9B=98?= =?UTF-8?q?=E4=BB=A5=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E5=AE=B9=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monitoring/unit/disk.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/monitoring/unit/disk.go b/monitoring/unit/disk.go index 887eac7..43021be 100644 --- a/monitoring/unit/disk.go +++ b/monitoring/unit/disk.go @@ -107,6 +107,12 @@ func isPhysicalDisk(part disk.PartitionStat) bool { } fstype := strings.ToLower(part.Fstype) + // // 针对 Linux autofs:它只是自动挂载的触发器,真实文件系统会作为单独分区出现。 + // 将 autofs 视为“非物理磁盘”可以避免重复统计容量。 + if fstype == "autofs" && !strings.HasPrefix(part.Device, "/dev/") { + return false + } + // 针对 Linux 下通过 ntfs-3g 挂载的 NTFS 分区 (fuseblk),这是实际物理磁盘,不应排除 if fstype == "fuseblk" { return true From 9e6d35411713ce930fecbccb627175c907c4d609 Mon Sep 17 00:00:00 2001 From: xxxizum1kxxx <244161265+xxxizum1kxxx@users.noreply.github.com> Date: Tue, 2 Dec 2025 19:57:33 +0800 Subject: [PATCH 4/4] =?UTF-8?q?Comment=EF=BC=9A=E6=B7=BB=E5=8A=A0=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monitoring/unit/disk.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/monitoring/unit/disk.go b/monitoring/unit/disk.go index 43021be..74f7d20 100644 --- a/monitoring/unit/disk.go +++ b/monitoring/unit/disk.go @@ -14,6 +14,7 @@ type DiskInfo struct { func Disk() DiskInfo { diskinfo := DiskInfo{} + // 获取所有分区,使用 true 避免物理磁盘被 gopsutil 错误排除 usage, err := disk.Partitions(true) if err != nil { diskinfo.Total = 0 @@ -107,7 +108,8 @@ func isPhysicalDisk(part disk.PartitionStat) bool { } fstype := strings.ToLower(part.Fstype) - // // 针对 Linux autofs:它只是自动挂载的触发器,真实文件系统会作为单独分区出现。 + + // 针对 Linux autofs:排除自动挂载的 trigger,真实文件系统会作为单独分区出现不会被排除。 // 将 autofs 视为“非物理磁盘”可以避免重复统计容量。 if fstype == "autofs" && !strings.HasPrefix(part.Device, "/dev/") { return false