diff --git a/info/v1/machine.go b/info/v1/machine.go index 7f50ce3b..f26291c1 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 50fbee24..b6c3f24f 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 547f1077..fb125816 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.