|
|
@@ -11,6 +11,7 @@ import (
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
+ "syscall"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
@@ -218,27 +219,21 @@ func getMemInfo() (int, string, string) {
|
|
|
}
|
|
|
|
|
|
func getDiskInfo() (int, string, string) {
|
|
|
- out, err := exec.Command("df", "-hP", "/").Output()
|
|
|
- if err != nil {
|
|
|
+ var fsStat syscall.Statfs_t
|
|
|
+ if err := syscall.Statfs("/", &fsStat); err != nil {
|
|
|
return 0, noValue, noValue
|
|
|
}
|
|
|
|
|
|
- lines := strings.Split(string(out), "\n")
|
|
|
- if len(lines) < 2 {
|
|
|
- return 0, noValue, noValue
|
|
|
- }
|
|
|
+ bsize := uint64(fsStat.Bsize)
|
|
|
+ used := (fsStat.Blocks - fsStat.Bfree) * bsize
|
|
|
+ avail := fsStat.Bavail * bsize
|
|
|
+ total := fsStat.Blocks * bsize
|
|
|
|
|
|
- f := strings.Fields(lines[1])
|
|
|
- if len(f) < 5 {
|
|
|
+ if used+avail == 0 {
|
|
|
return 0, noValue, noValue
|
|
|
}
|
|
|
|
|
|
- percent, err := strconv.Atoi(strings.TrimSuffix(f[4], "%"))
|
|
|
- if err != nil {
|
|
|
- percent = 0
|
|
|
- }
|
|
|
-
|
|
|
- return percent, f[2], f[1]
|
|
|
+ return int(used * 100 / (used + avail)), formatSize(used), formatSize(total)
|
|
|
}
|
|
|
|
|
|
func formatSize(size uint64) string {
|