analytic.go 523 B

1234567891011121314151617181920
  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, float64, error) {
  9. di, err := disk.GetInfo(path)
  10. if err != nil {
  11. return "", "", 0, err
  12. }
  13. percentage := (float64(di.Total-di.Free) / float64(di.Total)) * 100
  14. percentage, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", percentage), 64)
  15. return humanize.Bytes(di.Total-di.Free), humanize.Bytes(di.Total),
  16. percentage, nil
  17. }