Merge pull request #674 from lootek/more-vmstat

Add pages in/out/fault statistics (as read from vmstat)
tags/v2.19.04 v2.19.04
shirou 6 years ago committed by GitHub
commit fa9845945e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -84,6 +84,9 @@ type SwapMemoryStat struct {
UsedPercent float64 `json:"usedPercent"` UsedPercent float64 `json:"usedPercent"`
Sin uint64 `json:"sin"` Sin uint64 `json:"sin"`
Sout uint64 `json:"sout"` Sout uint64 `json:"sout"`
PgIn uint64 `json:"pgin"`
PgOut uint64 `json:"pgout"`
PgFault uint64 `json:"pgfault"`
} }
func (m VirtualMemoryStat) String() string { func (m VirtualMemoryStat) String() string {

@ -177,6 +177,24 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
continue continue
} }
ret.Sout = value * 4 * 1024 ret.Sout = value * 4 * 1024
case "pgpgin":
value, err := strconv.ParseUint(fields[1], 10, 64)
if err != nil {
continue
}
ret.PgIn = value * 4 * 1024
case "pgpgout":
value, err := strconv.ParseUint(fields[1], 10, 64)
if err != nil {
continue
}
ret.PgOut = value * 4 * 1024
case "pgfault":
value, err := strconv.ParseUint(fields[1], 10, 64)
if err != nil {
continue
}
ret.PgFault = value * 4 * 1024
} }
} }
return ret, nil return ret, nil

@ -89,8 +89,13 @@ func TestSwapMemoryStat_String(t *testing.T) {
Used: 30, Used: 30,
Free: 40, Free: 40,
UsedPercent: 30.1, UsedPercent: 30.1,
Sin: 1,
Sout: 2,
PgIn: 3,
PgOut: 4,
PgFault: 5,
} }
e := `{"total":10,"used":30,"free":40,"usedPercent":30.1,"sin":0,"sout":0}` e := `{"total":10,"used":30,"free":40,"usedPercent":30.1,"sin":1,"sout":2,"pgin":3,"pgout":4,"pgfault":5}`
if e != fmt.Sprintf("%v", v) { if e != fmt.Sprintf("%v", v) {
t.Errorf("SwapMemoryStat string is invalid: %v", v) t.Errorf("SwapMemoryStat string is invalid: %v", v)
} }

Loading…
Cancel
Save