analytic.go 636 B

1234567891011121314151617181920212223
  1. package tool
  2. import (
  3. "fmt"
  4. "github.com/dustin/go-humanize"
  5. "github.com/minio/minio/pkg/disk"
  6. "strconv"
  7. )
  8. func DiskUsage(path string) (string, string, string, error) {
  9. di, err := disk.GetInfo(path)
  10. if err != nil {
  11. return "", "", "", err
  12. }
  13. percentage := (float64(di.Total-di.Free) / float64(di.Total)) * 100
  14. fmt.Printf("%s of %s disk space used (%0.2f%%)\n",
  15. humanize.Bytes(di.Total-di.Free),
  16. humanize.Bytes(di.Total),
  17. percentage,
  18. )
  19. return humanize.Bytes(di.Total-di.Free), humanize.Bytes(di.Total),
  20. strconv.FormatFloat(percentage, 'f', 2, 64), nil
  21. }