mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
19 lines
527 B
Go
19 lines
527 B
Go
package tool
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/dustin/go-humanize"
|
|
"github.com/mackerelio/go-osstat/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
|
|
percentage, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", percentage), 64)
|
|
return humanize.Bytes(di.Total-di.Free), humanize.Bytes(di.Total),
|
|
percentage, nil
|
|
}
|