Merge pull request #674 from lootek/more-vmstat

Add pages in/out/fault statistics (as read from vmstat)
This commit is contained in:
shirou 2019-04-27 12:13:43 +09:00 committed by GitHub
commit fa9845945e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

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

View File

@ -177,6 +177,24 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
continue
}
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

View File

@ -89,8 +89,13 @@ func TestSwapMemoryStat_String(t *testing.T) {
Used: 30,
Free: 40,
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) {
t.Errorf("SwapMemoryStat string is invalid: %v", v)
}