mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
feat: 优化 CPU 和磁盘信息获取,增强对 Server 版本的支持,改进终端关闭逻辑
This commit is contained in:
@@ -2,7 +2,6 @@ package monitoring
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -22,24 +21,27 @@ func Cpu() CpuInfo {
|
||||
if err != nil {
|
||||
cpuinfo.CPUName = "Unknown"
|
||||
}
|
||||
// multiple CPU
|
||||
// 多个 CPU
|
||||
if len(info) > 1 {
|
||||
cpuCountMap := make(map[string]int)
|
||||
for _, cpu := range info {
|
||||
cpuCountMap[cpu.ModelName]++
|
||||
}
|
||||
for modelName, count := range cpuCountMap {
|
||||
if count > 1 {
|
||||
cpuinfo.CPUName += modelName + " x " + strconv.Itoa(count) + ", "
|
||||
} else {
|
||||
cpuinfo.CPUName += modelName + ", "
|
||||
/*
|
||||
// multiple CPU
|
||||
// 多个 CPU
|
||||
if len(info) > 1 {
|
||||
cpuCountMap := make(map[string]int)
|
||||
for _, cpu := range info {
|
||||
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 {
|
||||
cpuinfo.CPUName = info[0].ModelName
|
||||
}
|
||||
cpuinfo.CPUName = cpuinfo.CPUName[:len(cpuinfo.CPUName)-2] // Remove trailing comma and space
|
||||
} else if len(info) == 1 {
|
||||
cpuinfo.CPUName = info[0].ModelName
|
||||
}
|
||||
*/
|
||||
cpuinfo.CPUName = info[0].ModelName
|
||||
|
||||
cpuinfo.CPUName = strings.TrimSpace(cpuinfo.CPUName)
|
||||
|
||||
|
Reference in New Issue
Block a user