[FIX] fix get node system info bug

This commit is contained in:
barnettZQG 2018-07-16 12:16:16 +08:00
parent a217cf54c2
commit 9a5bd730d8
4 changed files with 7 additions and 5 deletions

View File

@ -58,6 +58,7 @@ type etcdClusterClient struct {
func (e *etcdClusterClient) UpdateStatus(n *HostNode) error { func (e *etcdClusterClient) UpdateStatus(n *HostNode) error {
n.UpTime = time.Now() n.UpTime = time.Now()
n.Alived = true
if err := e.Update(n); err != nil { if err := e.Update(n); err != nil {
return err return err
} }

View File

@ -131,7 +131,7 @@ type NodeSystemInfo struct {
// The Architecture reported by the node // The Architecture reported by the node
Architecture string `json:"architecture"` Architecture string `json:"architecture"`
MemorySize uint32 `json:"memorySize"` MemorySize uint64 `json:"memorySize"`
} }
//Decode decode node info //Decode decode node info

View File

@ -22,9 +22,9 @@ package info
import ( import (
"bufio" "bufio"
"exec"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec"
"runtime" "runtime"
"strings" "strings"
"syscall" "syscall"
@ -61,18 +61,18 @@ func readOS() map[string]string {
if err != nil { if err != nil {
return info return info
} }
lines := strings.Split(line, "=") lines := strings.Split(string(line), "=")
if len(lines) >= 2 { if len(lines) >= 2 {
info[lines[0]] = lines[1] info[lines[0]] = lines[1]
} }
} }
} }
func getMemory() (total uint32, free uint32) { func getMemory() (total uint64, free uint64) {
sysInfo := new(syscall.Sysinfo_t) sysInfo := new(syscall.Sysinfo_t)
err := syscall.Sysinfo(sysInfo) err := syscall.Sysinfo(sysInfo)
if err == nil { 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 return 0, 0
} }

View File

@ -141,6 +141,7 @@ func (n *NodeManager) heartbeat() {
if err := n.cluster.UpdateStatus(&n.HostNode); err != nil { if err := n.cluster.UpdateStatus(&n.HostNode); err != nil {
logrus.Errorf("update node status error %s", err.Error()) logrus.Errorf("update node status error %s", err.Error())
} }
logrus.Info("update node status success")
return nil return nil
}, time.Second*time.Duration(n.cfg.TTL)) }, time.Second*time.Duration(n.cfg.TTL))
} }