Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 9626a4f

Browse files
committed
[agent]修复CPU在老的windows系统上的计算错误
1 parent d7dabac commit 9626a4f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

teaconfigs/agents/source_cpu.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/iwind/TeaGo/logs"
88
"github.com/iwind/TeaGo/maps"
99
"github.com/shirou/gopsutil/cpu"
10+
"runtime"
1011
"sync"
1112
"time"
1213
)
@@ -67,6 +68,11 @@ func (this *CPUSource) Execute(params map[string]string) (value interface{}, err
6768
}
6869
sum := float64(0)
6970
for _, percent := range percents {
71+
// 修复Windows上可能遇到的100%的Bug
72+
if runtime.GOOS == "windows" && percent > 99.9 {
73+
percent = 0
74+
}
75+
7076
sum += percent
7177
}
7278
avg := sum / float64(len(percents))

0 commit comments

Comments
 (0)