From e1d03ad65aa69cfa4a40415cb6d44f2935749e0d Mon Sep 17 00:00:00 2001 From: zhoujunhao <18853925545@163.com> Date: Wed, 17 Oct 2018 17:25:14 +0800 Subject: [PATCH 1/3] [FIX] Fix the problem of inaccurate host memory --- node/nodem/info/info_linux.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/nodem/info/info_linux.go b/node/nodem/info/info_linux.go index 03f6fd684..a4353d1df 100644 --- a/node/nodem/info/info_linux.go +++ b/node/nodem/info/info_linux.go @@ -69,10 +69,10 @@ func readOS() map[string]string { } func getMemory() (total uint64, free uint64) { - sysInfo := new(syscall.Sysinfo_t) + sysInfo := syscall.Sysinfo_t{} err := syscall.Sysinfo(sysInfo) if err == nil { - return sysInfo.Totalram * uint64(syscall.Getpagesize()), sysInfo.Freeram * uint64(syscall.Getpagesize()) + return uint64(sysInfo.Totalram) * uint64(sysInfo.Unit), sysInfo.Freeram * uint64(syscall.Getpagesize()) } return 0, 0 } From 2f65f80d1f15af6b7688f86e764a2966caa96a57 Mon Sep 17 00:00:00 2001 From: zhoujunhao <18853925545@163.com> Date: Wed, 17 Oct 2018 17:33:52 +0800 Subject: [PATCH 2/3] [FIX] Fix the problem of inaccurate host memory --- node/nodem/info/info_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/nodem/info/info_linux.go b/node/nodem/info/info_linux.go index a4353d1df..3092a9cec 100644 --- a/node/nodem/info/info_linux.go +++ b/node/nodem/info/info_linux.go @@ -69,7 +69,7 @@ func readOS() map[string]string { } func getMemory() (total uint64, free uint64) { - sysInfo := syscall.Sysinfo_t{} + sysInfo := new(syscall.Sysinfo_t) err := syscall.Sysinfo(sysInfo) if err == nil { return uint64(sysInfo.Totalram) * uint64(sysInfo.Unit), sysInfo.Freeram * uint64(syscall.Getpagesize()) From 0b144b94ff31f8894c08f8b620abee8533280be6 Mon Sep 17 00:00:00 2001 From: zhoujunhao <18853925545@163.com> Date: Wed, 17 Oct 2018 18:22:24 +0800 Subject: [PATCH 3/3] [ADD] Add cpu number information --- node/nodem/client/node.go | 1 + node/nodem/info/info_linux.go | 1 + 2 files changed, 2 insertions(+) diff --git a/node/nodem/client/node.go b/node/nodem/client/node.go index 19b32c725..3d8ffd4fe 100644 --- a/node/nodem/client/node.go +++ b/node/nodem/client/node.go @@ -153,6 +153,7 @@ type NodeSystemInfo struct { Architecture string `json:"architecture"` MemorySize uint64 `json:"memorySize"` + NumCPU int64 `json:"cpu_num"` } //Decode decode node info diff --git a/node/nodem/info/info_linux.go b/node/nodem/info/info_linux.go index 3092a9cec..b9d96bfce 100644 --- a/node/nodem/info/info_linux.go +++ b/node/nodem/info/info_linux.go @@ -45,6 +45,7 @@ func GetSystemInfo() (info client.NodeSystemInfo) { } info.OperatingSystem = runtime.GOOS info.MemorySize, _ = getMemory() + info.NumCPU = int64(runtime.NumCPU()) return info }