Skip to content

Commit

Permalink
refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
shirou committed Sep 19, 2014
1 parent 90b8a21 commit b2dc569
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 39 deletions.
14 changes: 7 additions & 7 deletions disk_linux.go
Expand Up @@ -78,13 +78,13 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
return ret, err
}
d := DiskIOCountersStat{
ReadBytes: uint64(rbytes) * SectorSize,
WriteBytes: uint64(wbytes) * SectorSize,
ReadCount: uint64(reads),
WriteCount: uint64(writes),
ReadTime: uint64(rtime),
WriteTime: uint64(wtime),
IoTime: uint64(iotime),
ReadBytes: rbytes * SectorSize,
WriteBytes: wbytes * SectorSize,
ReadCount: reads,
WriteCount: writes,
ReadTime: rtime,
WriteTime: wtime,
IoTime: iotime,
}
if d == empty {
continue
Expand Down
42 changes: 10 additions & 32 deletions mem_linux.go
Expand Up @@ -22,45 +22,23 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
value := strings.TrimSpace(fields[1])
value = strings.Replace(value, " kB", "", -1)

t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, err
}
switch key {
case "MemTotal":
ret.Total = mustParseUint64(value) * 1000
t, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return ret, err
}
ret.Total = uint64(t) * 1000
ret.Total = t * 1000
case "MemFree":
ret.Free = mustParseUint64(value) * 1000
t, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return ret, err
}
ret.Free = uint64(t) * 1000
ret.Free = t * 1000
case "Buffers":
t, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return ret, err
}
ret.Buffers = uint64(t) * 1000
ret.Buffers = t * 1000
case "Cached":
t, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return ret, err
}
ret.Cached = uint64(t) * 1000
ret.Cached = t * 1000
case "Active":
t, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return ret, err
}
ret.Active = uint64(t) * 1000
ret.Active = t * 1000
case "Inactive":
t, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return ret, err
}
ret.Inactive = uint64(t) * 1000
ret.Inactive = t * 1000
}
}
ret.Available = ret.Free + ret.Buffers + ret.Cached
Expand Down

0 comments on commit b2dc569

Please sign in to comment.