From 86712e93a51c8ea3239d63e17110f4871c685f6b Mon Sep 17 00:00:00 2001 From: naiba Date: Fri, 6 Nov 2020 20:56:46 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20CPU=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/monitor.go | 42 ++++++++++++++++++++------------ resource/template/page/home.html | 2 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/model/monitor.go b/model/monitor.go index f2e7a94..2b59a10 100644 --- a/model/monitor.go +++ b/model/monitor.go @@ -1,6 +1,10 @@ package model -import pb "github.com/p14yground/nezha/proto" +import ( + "fmt" + + pb "github.com/p14yground/nezha/proto" +) const ( _ = iota @@ -56,9 +60,9 @@ type Host struct { Platform string PlatformVersion string CPU []string - MemTotal uint64 - DiskTotal uint64 - SwapTotal uint64 + MemTotal uint64 + DiskTotal uint64 + SwapTotal uint64 Arch string Virtualization string BootTime uint64 @@ -73,9 +77,9 @@ func (h *Host) PB() *pb.Host { Platform: h.Platform, PlatformVersion: h.PlatformVersion, Cpu: h.CPU, - MemTotal: h.MemTotal, - DiskTotal: h.DiskTotal, - SwapTotal: h.SwapTotal, + MemTotal: h.MemTotal, + DiskTotal: h.DiskTotal, + SwapTotal: h.SwapTotal, Arch: h.Arch, Virtualization: h.Virtualization, BootTime: h.BootTime, @@ -85,16 +89,27 @@ func (h *Host) PB() *pb.Host { } } - // PB2Host ... 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: h.GetCpu(), - MemTotal: h.GetMemTotal(), - DiskTotal: h.GetDiskTotal(), - SwapTotal: h.GetSwapTotal(), + CPU: distCpu, + MemTotal: h.GetMemTotal(), + DiskTotal: h.GetDiskTotal(), + SwapTotal: h.GetSwapTotal(), Arch: h.GetArch(), Virtualization: h.GetVirtualization(), BootTime: h.GetBootTime(), @@ -103,6 +118,3 @@ func PB2Host(h *pb.Host) Host { Version: h.GetVersion(), } } - - - diff --git a/resource/template/page/home.html b/resource/template/page/home.html index ba32d97..e6cd3b8 100644 --- a/resource/template/page/home.html +++ b/resource/template/page/home.html @@ -23,7 +23,7 @@ class='arrow alternate circle down outline icon'>@#formatByteSize(server.State.NetInTransfer)#@@#formatByteSize(server.State.NetOutTransfer)#@
启动:@# formatTimestamp(server.Host.BootTime) #@
- 版本:@#'v'+server.Host.Version#@
+ 版本:@#server.Host.Version#@