Skip to content

Commit

Permalink
Merge pull request #1068 from krhubert/master
Browse files Browse the repository at this point in the history
Use uint64 for Memory Stats
  • Loading branch information
jimmidyson committed Jan 27, 2016
2 parents c2eaabd + 7d05357 commit 1f6f660
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion info/v1/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion info/v2/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
16 changes: 8 additions & 8 deletions utils/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 1f6f660

Please sign in to comment.