mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
fix: #3 修改CPU名称识别的逻辑
This commit is contained in:
@@ -2,6 +2,7 @@ package monitoring
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -24,8 +25,16 @@ func Cpu() CpuInfo {
|
|||||||
// multiple CPU
|
// multiple CPU
|
||||||
// 多个 CPU
|
// 多个 CPU
|
||||||
if len(info) > 1 {
|
if len(info) > 1 {
|
||||||
|
cpuCountMap := make(map[string]int)
|
||||||
for _, cpu := range info {
|
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
|
cpuinfo.CPUName = cpuinfo.CPUName[:len(cpuinfo.CPUName)-2] // Remove trailing comma and space
|
||||||
} else if len(info) == 1 {
|
} else if len(info) == 1 {
|
||||||
|
Reference in New Issue
Block a user