From 9abb5c0f72159c4913ad09ce211515f78cb1e5d9 Mon Sep 17 00:00:00 2001 From: naiba Date: Fri, 5 Jan 2024 15:58:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcpu=E6=A0=B8=E5=BF=83?= =?UTF-8?q?=E6=95=B0=E8=AF=86=E5=88=AB=E9=94=99=E8=AF=AF=20(#7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix distinguish kvm host as guset * Fix spelling errors * Update .gitignore * 修复cpu核心数读取错误 * 添加判断ci的长度 --- README.md | 6 +++--- pkg/monitor/monitor.go | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 49b1491..d4282d6 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,12 @@ Agent of Nezha Monitoring naiba - - zhangnew - Crazy + + zhangnew + 卖女孩的小火柴 diff --git a/pkg/monitor/monitor.go b/pkg/monitor/monitor.go index 6900184..35d11ee 100644 --- a/pkg/monitor/monitor.go +++ b/pkg/monitor/monitor.go @@ -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)