From 7d053578d455b71cc4dc68642ebe00dd99e15262 Mon Sep 17 00:00:00 2001 From: Hubert Krauze Date: Wed, 20 Jan 2016 08:46:42 +0100 Subject: [PATCH] Use uint64 for Memory Stats --- info/v1/machine.go | 2 +- info/v2/machine.go | 2 +- utils/machine/machine.go | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/info/v1/machine.go b/info/v1/machine.go index 7f50ce3b24..f26291c112 100644 --- a/info/v1/machine.go +++ b/info/v1/machine.go @@ -136,7 +136,7 @@ type MachineInfo struct { CpuFrequency uint64 `json:"cpu_frequency_khz"` // The amount of memory (in bytes) in this machine - MemoryCapacity int64 `json:"memory_capacity"` + MemoryCapacity uint64 `json:"memory_capacity"` // The machine id MachineID string `json:"machine_id"` diff --git a/info/v2/machine.go b/info/v2/machine.go index 50fbee2441..b6c3f24f35 100644 --- a/info/v2/machine.go +++ b/info/v2/machine.go @@ -41,7 +41,7 @@ type Attributes struct { CpuFrequency uint64 `json:"cpu_frequency_khz"` // The amount of memory (in bytes) in this machine - MemoryCapacity int64 `json:"memory_capacity"` + MemoryCapacity uint64 `json:"memory_capacity"` // The machine id MachineID string `json:"machine_id"` diff --git a/utils/machine/machine.go b/utils/machine/machine.go index 547f1077db..fb12581693 100644 --- a/utils/machine/machine.go +++ b/utils/machine/machine.go @@ -82,8 +82,8 @@ func GetClockSpeed(procInfo []byte) (uint64, error) { } // GetMachineMemoryCapacity returns the machine's total memory from /proc/meminfo. -// Returns the total memory capacity as an int64 (number of bytes). -func GetMachineMemoryCapacity() (int64, error) { +// Returns the total memory capacity as an uint64 (number of bytes). +func GetMachineMemoryCapacity() (uint64, error) { out, err := ioutil.ReadFile("/proc/meminfo") if err != nil { return 0, err @@ -97,8 +97,8 @@ func GetMachineMemoryCapacity() (int64, error) { } // GetMachineSwapCapacity returns the machine's total swap from /proc/meminfo. -// Returns the total swap capacity as an int64 (number of bytes). -func GetMachineSwapCapacity() (int64, error) { +// Returns the total swap capacity as an uint64 (number of bytes). +func GetMachineSwapCapacity() (uint64, error) { out, err := ioutil.ReadFile("/proc/meminfo") if err != nil { return 0, err @@ -113,14 +113,14 @@ func GetMachineSwapCapacity() (int64, error) { // parseCapacity matches a Regexp in a []byte, returning the resulting value in bytes. // Assumes that the value matched by the Regexp is in KB. -func parseCapacity(b []byte, r *regexp.Regexp) (int64, error) { +func parseCapacity(b []byte, r *regexp.Regexp) (uint64, error) { matches := r.FindSubmatch(b) if len(matches) != 2 { - return -1, fmt.Errorf("failed to match regexp in output: %q", string(b)) + return 0, fmt.Errorf("failed to match regexp in output: %q", string(b)) } - m, err := strconv.ParseInt(string(matches[1]), 10, 64) + m, err := strconv.ParseUint(string(matches[1]), 10, 64) if err != nil { - return -1, err + return 0, err } // Convert to bytes.