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

* fix distinguish kvm host as guset

* Fix spelling errors

* Update .gitignore

* 修复cpu核心数读取错误

* 添加判断ci的长度
This commit is contained in:
naiba 2024-01-05 15:58:43 +08:00
parent 1342eaeb38
commit 9abb5c0f72
2 changed files with 9 additions and 11 deletions

View File

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

View File

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