Merge pull request #23 from def/master

[linux] fill SwapMemoryStat.Sin/Sout from /proc/vmstat
pull/26/head
shirou 11 years ago
commit 539c144016

@ -65,6 +65,26 @@ func SwapMemory() (*SwapMemoryStat, error) {
} else {
ret.UsedPercent = 0
}
lines, _ := readLines("/proc/vmstat")
for _, l := range lines {
fields := strings.Fields(l)
if len(fields) < 2 {
continue
}
switch fields[0] {
case "pswpin":
value, err := strconv.ParseUint(fields[1], 10, 64)
if err != nil {
continue
}
ret.Sin = value * 4 * 1024
case "pswpout":
value, err := strconv.ParseUint(fields[1], 10, 64)
if err != nil {
continue
}
ret.Sout = value * 4 * 1024
}
}
return ret, nil
}

@ -33,10 +33,10 @@ type RlimitStat struct {
}
type IOCountersStat struct {
ReadCount int32 `json:"read_count"`
WriteCount int32 `json:"write_count"`
ReadBytes int32 `json:"read_bytes"`
WriteBytes int32 `json:"write_bytes"`
ReadCount uint64 `json:"read_count"`
WriteCount uint64 `json:"write_count"`
ReadBytes uint64 `json:"read_bytes"`
WriteBytes uint64 `json:"write_bytes"`
}
type NumCtxSwitchesStat struct {

@ -346,24 +346,27 @@ func (p *Process) fillFromIO() (*IOCountersStat, error) {
ret := &IOCountersStat{}
for _, line := range lines {
field := strings.Split(line, ":")
field := strings.Fields(line)
if len(field) < 2 {
continue
}
t, err := strconv.ParseInt(strings.Trim(field[1], " \t"), 10, 32)
t, err := strconv.ParseUint(field[1], 10, 64)
if err != nil {
return nil, err
}
switch field[0] {
case "rchar":
ret.ReadCount = int32(t)
case "wchar":
ret.WriteCount = int32(t)
param := field[0]
if strings.HasSuffix(param, ":") {
param = param[:len(param)-1]
}
switch param {
case "syscr":
ret.ReadCount = t
case "syscw":
ret.WriteCount = t
case "read_bytes":
ret.ReadBytes = int32(t)
ret.ReadBytes = t
case "write_bytes":
ret.WriteBytes = int32(t)
ret.WriteBytes = t
}
}

Loading…
Cancel
Save