Revert "修复cpu核心数识别错误 (#7)"

This reverts commit 9abb5c0f72159c4913ad09ce211515f78cb1e5d9.
This commit is contained in:
naiba 2024-01-10 09:34:56 +08:00
parent 9abb5c0f72
commit af85ddd97e
2 changed files with 11 additions and 9 deletions

View File

@ -7,12 +7,12 @@ Agent of Nezha Monitoring
<!--GAMFC_DELIMITER--><a href="https://github.com/naiba" title="naiba">
<img src="https://avatars.githubusercontent.com/u/29243953?v=4" width="50;" alt="naiba"/>
</a>
<a href="https://github.com/wwng2333" title="Crazy">
<img src="https://avatars.githubusercontent.com/u/17147265?v=4" width="50;" alt="Crazy"/>
</a>
<a href="https://github.com/zhangnew" title="zhangnew">
<img src="https://avatars.githubusercontent.com/u/9146834?v=4" width="50;" alt="zhangnew"/>
</a>
<a href="https://github.com/wwng2333" title="Crazy">
<img src="https://avatars.githubusercontent.com/u/17147265?v=4" width="50;" alt="Crazy"/>
</a>
<a href="https://github.com/Erope" title="卖女孩的小火柴">
<img src="https://avatars.githubusercontent.com/u/44471469?v=4" width="50;" alt="卖女孩的小火柴"/>
</a><!--GAMFC_DELIMITER_END-->

View File

@ -58,15 +58,17 @@ func GetHost(agentConfig *model.AgentConfig) *model.Host {
ret.BootTime = hi.BootTime
}
cpuModelCount := make(map[string]int)
ci, err := cpu.Info()
if err != nil {
println("cpu.Info error:", err)
}
count, err := cpu.Counts(false)
if err != nil {
println("cpu.Counts error:", err)
} else if len(ci) > 0 {
ret.CPU = append(ret.CPU, fmt.Sprintf("%s %d %s Core", ci[0].ModelName, count, cpuType))
} else {
for i := 0; i < len(ci); i++ {
cpuModelCount[ci[i].ModelName]++
}
for model, count := range cpuModelCount {
ret.CPU = append(ret.CPU, fmt.Sprintf("%s %d %s Core", model, count, cpuType))
}
}
ret.DiskTotal, _ = getDiskTotalAndUsed(agentConfig)