mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
refactoring.
This commit is contained in:
parent
90b8a2160b
commit
b2dc569885
@ -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
|
||||
|
42
mem_linux.go
42
mem_linux.go
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user