修复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
+6 -8
View File
@@ -58,17 +58,15 @@ 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)
} 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))
}
}
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))
}
ret.DiskTotal, _ = getDiskTotalAndUsed(agentConfig)