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