1// +build !openbsd !arm 2 3package diagnose 4 5import ( 6 "context" 7 "fmt" 8 "strings" 9 10 "github.com/dustin/go-humanize" 11 "github.com/shirou/gopsutil/disk" 12) 13 14func diskUsage(ctx context.Context) error { 15 // Disk usage 16 partitions, err := disk.Partitions(false) 17 if err != nil { 18 return err 19 } 20 21 partitionExcludes := []string{"/boot"} 22partLoop: 23 for _, partition := range partitions { 24 for _, exc := range partitionExcludes { 25 if strings.HasPrefix(partition.Mountpoint, exc) { 26 continue partLoop 27 } 28 } 29 usage, err := disk.Usage(partition.Mountpoint) 30 testName := "Check Disk Usage" 31 if err != nil { 32 Warn(ctx, fmt.Sprintf("Could not obtain partition usage for %s: %v.", partition.Mountpoint, err)) 33 } else { 34 if usage.UsedPercent > 95 { 35 SpotWarn(ctx, testName, fmt.Sprintf(partition.Mountpoint+" is %.2f percent full.", usage.UsedPercent), 36 Advice("It is recommended to have more than five percent of the partition free.")) 37 } else if usage.Free < 1<<30 { 38 SpotWarn(ctx, testName, fmt.Sprintf(partition.Mountpoint+" has %s free.", humanize.Bytes(usage.Free)), 39 Advice("It is recommended to have at least 1 GB of space free per partition.")) 40 } else { 41 SpotOk(ctx, testName, partition.Mountpoint+" usage ok.") 42 } 43 } 44 45 } 46 return nil 47} 48