🚸 chore: refactor CPU model string

This commit is contained in:
naiba
2021-02-27 19:24:19 +08:00
parent 2133973579
commit dbf62991a5
5 changed files with 44 additions and 24 deletions

View File

@@ -1,8 +1,6 @@
package model
import (
"fmt"
pb "github.com/naiba/nezha/proto"
)
@@ -85,22 +83,10 @@ func (h *Host) PB() *pb.Host {
}
func PB2Host(h *pb.Host) Host {
cpuCount := make(map[string]int, 0)
cpus := h.GetCpu()
for _, u := range cpus {
cpuCount[u]++
}
var distCpu []string
for u, num := range cpuCount {
distCpu = append(distCpu, fmt.Sprintf("%sx%d", u, num))
}
return Host{
Platform: h.GetPlatform(),
PlatformVersion: h.GetPlatformVersion(),
CPU: distCpu,
CPU: h.GetCpu(),
MemTotal: h.GetMemTotal(),
DiskTotal: h.GetDiskTotal(),
SwapTotal: h.GetSwapTotal(),