fix: #3 修改CPU名称识别的逻辑

This commit is contained in:
Akizon77
2025-05-06 21:08:01 +08:00
parent 2cc6534177
commit 180586d8aa

View File

@@ -2,6 +2,7 @@ package monitoring
import (
"runtime"
"strconv"
"strings"
"time"
@@ -24,8 +25,16 @@ func Cpu() CpuInfo {
// multiple CPU
// 多个 CPU
if len(info) > 1 {
cpuCountMap := make(map[string]int)
for _, cpu := range info {
cpuinfo.CPUName += cpu.ModelName + ", "
cpuCountMap[cpu.ModelName]++
}
for modelName, count := range cpuCountMap {
if count > 1 {
cpuinfo.CPUName += modelName + " x " + strconv.Itoa(count) + ", "
} else {
cpuinfo.CPUName += modelName + ", "
}
}
cpuinfo.CPUName = cpuinfo.CPUName[:len(cpuinfo.CPUName)-2] // Remove trailing comma and space
} else if len(info) == 1 {