From 9a5bd730d8bc7b6190f24c93d11e6ad29ccc7ea5 Mon Sep 17 00:00:00 2001 From: barnettZQG Date: Mon, 16 Jul 2018 12:16:16 +0800 Subject: [PATCH] [FIX] fix get node system info bug --- node/nodem/client/cluster_client.go | 1 + node/nodem/client/node.go | 2 +- node/nodem/info/info_linux.go | 8 ++++---- node/nodem/node_manager.go | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/node/nodem/client/cluster_client.go b/node/nodem/client/cluster_client.go index 7e605c4a7..717a92147 100644 --- a/node/nodem/client/cluster_client.go +++ b/node/nodem/client/cluster_client.go @@ -58,6 +58,7 @@ type etcdClusterClient struct { func (e *etcdClusterClient) UpdateStatus(n *HostNode) error { n.UpTime = time.Now() + n.Alived = true if err := e.Update(n); err != nil { return err } diff --git a/node/nodem/client/node.go b/node/nodem/client/node.go index c16132cbb..036530e20 100644 --- a/node/nodem/client/node.go +++ b/node/nodem/client/node.go @@ -131,7 +131,7 @@ type NodeSystemInfo struct { // The Architecture reported by the node Architecture string `json:"architecture"` - MemorySize uint32 `json:"memorySize"` + MemorySize uint64 `json:"memorySize"` } //Decode decode node info diff --git a/node/nodem/info/info_linux.go b/node/nodem/info/info_linux.go index aecd15de9..03f6fd684 100644 --- a/node/nodem/info/info_linux.go +++ b/node/nodem/info/info_linux.go @@ -22,9 +22,9 @@ package info import ( "bufio" - "exec" "io/ioutil" "os" + "os/exec" "runtime" "strings" "syscall" @@ -61,18 +61,18 @@ func readOS() map[string]string { if err != nil { return info } - lines := strings.Split(line, "=") + lines := strings.Split(string(line), "=") if len(lines) >= 2 { info[lines[0]] = lines[1] } } } -func getMemory() (total uint32, free uint32) { +func getMemory() (total uint64, free uint64) { sysInfo := new(syscall.Sysinfo_t) err := syscall.Sysinfo(sysInfo) if err == nil { - return sysInfo.Totalram * uint32(syscall.Getpagesize()), sysInfo.Freeram * uint32(syscall.Getpagesize()) + return sysInfo.Totalram * uint64(syscall.Getpagesize()), sysInfo.Freeram * uint64(syscall.Getpagesize()) } return 0, 0 } diff --git a/node/nodem/node_manager.go b/node/nodem/node_manager.go index 78206f77e..22cc890e7 100644 --- a/node/nodem/node_manager.go +++ b/node/nodem/node_manager.go @@ -141,6 +141,7 @@ func (n *NodeManager) heartbeat() { if err := n.cluster.UpdateStatus(&n.HostNode); err != nil { logrus.Errorf("update node status error %s", err.Error()) } + logrus.Info("update node status success") return nil }, time.Second*time.Duration(n.cfg.TTL)) }