diff --git a/mem/mem.go b/mem/mem.go index 995364f..8d1c234 100644 --- a/mem/mem.go +++ b/mem/mem.go @@ -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 { diff --git a/mem/mem_linux.go b/mem/mem_linux.go index f5df35b..7785c50 100644 --- a/mem/mem_linux.go +++ b/mem/mem_linux.go @@ -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 diff --git a/mem/mem_test.go b/mem/mem_test.go index 5a31761..536508a 100644 --- a/mem/mem_test.go +++ b/mem/mem_test.go @@ -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) }