nginx-ui/server/tool/analytic.go
2021-03-16 20:36:27 +08:00

25 lines
680 B
Go

package tool
import (
"fmt"
"github.com/dustin/go-humanize"
"github.com/minio/minio/pkg/disk"
"strconv"
)
func DiskUsage(path string) (string, string, float64, error) {
di, err := disk.GetInfo(path)
if err != nil {
return "", "", 0, err
}
percentage := (float64(di.Total-di.Free) / float64(di.Total)) * 100
fmt.Printf("%s of %s disk space used (%0.2f%%)\n",
humanize.Bytes(di.Total-di.Free),
humanize.Bytes(di.Total),
percentage,
)
percentage, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", percentage), 64)
return humanize.Bytes(di.Total-di.Free), humanize.Bytes(di.Total),
percentage, nil
}