孟令鑫 1 rok temu
rodzic
commit
a5c207cc94
1 zmienionych plików z 4 dodań i 6 usunięć
  1. 4 6
      common/util/u_disk.go

+ 4 - 6
common/util/u_disk.go

@@ -1,20 +1,18 @@
 package util
 
 import (
-	"cicv-data-closedloop/kinglong/common/log"
 	"os/exec"
 	"strconv"
 	"strings"
 )
 
 // GetDiskUsagePercent 获取磁盘使用率
-func GetDiskUsagePercent() float64 {
+func GetDiskUsagePercent() (float64, error) {
 	// 执行 df 命令获取磁盘使用情况
 	cmd := exec.Command("df", "--total")
 	output, err := cmd.Output()
 	if err != nil {
-		log.GlobalLogger.Info("执行命令失败:", err)
-		return 0.0
+		return 0.0, err
 	}
 
 	// 解析 df 命令输出,计算磁盘占比
@@ -28,8 +26,8 @@ func GetDiskUsagePercent() float64 {
 			usedPercent := (used / total) * 100
 
 			//fmt.Printf("文件系统 %s 已使用 %.2f%%\n", filesystem, usedPercent)
-			return usedPercent
+			return usedPercent, err
 		}
 	}
-	return 0.0
+	return 0.0, nil
 }