Add pgmajfault to data returned by vmstat on Linux

pull/882/head
James Bebbington 5 years ago
parent 987c949880
commit 16fdb92bfc

@ -88,6 +88,7 @@ type SwapMemoryStat struct {
PgIn uint64 `json:"pgin"` PgIn uint64 `json:"pgin"`
PgOut uint64 `json:"pgout"` PgOut uint64 `json:"pgout"`
PgFault uint64 `json:"pgfault"` PgFault uint64 `json:"pgfault"`
PgMajFault uint64 `json:"pgmajfault"`
} }
func (m VirtualMemoryStat) String() string { func (m VirtualMemoryStat) String() string {

@ -232,6 +232,12 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
continue continue
} }
ret.PgFault = value * 4 * 1024 ret.PgFault = value * 4 * 1024
case "pgmajfault":
value, err := strconv.ParseUint(fields[1], 10, 64)
if err != nil {
continue
}
ret.PgMajFault = value * 4 * 1024
} }
} }
return ret, nil return ret, nil

@ -94,8 +94,9 @@ func TestSwapMemoryStat_String(t *testing.T) {
PgIn: 3, PgIn: 3,
PgOut: 4, PgOut: 4,
PgFault: 5, PgFault: 5,
PgMajFault: 6,
} }
e := `{"total":10,"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":1,"sout":2,"pgin":3,"pgout":4,"pgfault":5,"pgmajfault":6}`
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