fix: 修复GPU使用率检测

This commit is contained in:
spiritlhl
2025-03-30 04:52:49 +00:00
parent 3b9fe7c34a
commit d0a37ca0c8
2 changed files with 4 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import (
"testing"
)
// 本文件夹 network 修改需要同步 https://github.com/oneclickvirt/security 否则 goecs 无法使用
func TestIpv4SecurityCheck(t *testing.T) {
// 全项测试
ipInfo, _, _ := NetworkCheck("both", false, "zh")

View File

@@ -43,7 +43,6 @@ func updateGPUStat(gpuStat *uint64, wg *sync.WaitGroup) {
return
}
defer atomic.StoreInt32(&updateGPUStatus, 0)
for statDataFetchAttempts["GPU"] < maxDeviceDataFetchAttempts {
gs, err := gpustat.GetGPUStat()
if err != nil {
@@ -74,7 +73,9 @@ func getGPUInfo(ret *model.SystemInfo) (*model.SystemInfo, error) {
wg.Add(1)
go updateGPUStat(&gpuStat, &wg)
wg.Wait() // 等待 updateGPUStat 完成
ret.GpuStats = fmt.Sprintf("%f", math.Float64frombits(gpuStat))
if math.Float64frombits(gpuStat) > 0 {
ret.GpuStats = fmt.Sprintf("%f", math.Float64frombits(gpuStat))
}
return ret, nil
} else {
hostDataFetchAttempts["GPU"]++