From 16fdb92bfc02c1fc5f3852cfaa63bb9f8ce75979 Mon Sep 17 00:00:00 2001 From: James Bebbington Date: Mon, 25 May 2020 17:15:30 +1000 Subject: [PATCH] Add pgmajfault to data returned by vmstat on Linux --- mem/mem.go | 1 + mem/mem_linux.go | 6 ++++++ mem/mem_test.go | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mem/mem.go b/mem/mem.go index 8e444ba..f9c95fc 100644 --- a/mem/mem.go +++ b/mem/mem.go @@ -88,6 +88,7 @@ type SwapMemoryStat struct { PgIn uint64 `json:"pgin"` PgOut uint64 `json:"pgout"` PgFault uint64 `json:"pgfault"` + PgMajFault uint64 `json:"pgmajfault"` } func (m VirtualMemoryStat) String() string { diff --git a/mem/mem_linux.go b/mem/mem_linux.go index 66ccca9..72faf22 100644 --- a/mem/mem_linux.go +++ b/mem/mem_linux.go @@ -232,6 +232,12 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) { continue } 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 diff --git a/mem/mem_test.go b/mem/mem_test.go index 29d6c21..4a8a95c 100644 --- a/mem/mem_test.go +++ b/mem/mem_test.go @@ -94,8 +94,9 @@ func TestSwapMemoryStat_String(t *testing.T) { PgIn: 3, PgOut: 4, 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) { t.Errorf("SwapMemoryStat string is invalid: %v", v) }