From 5b52fbbea53fdce4dbd3edc950af892f86a6a8ae Mon Sep 17 00:00:00 2001 From: Olivier Vielpeau Date: Tue, 26 Dec 2017 16:09:49 +0100 Subject: [PATCH] [mem] Add commit-related stats to VirtualMemoryStat on Linux --- mem/mem.go | 2 ++ mem/mem_linux.go | 4 ++++ mem/mem_test.go | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mem/mem.go b/mem/mem.go index 87dfb53..01f3570 100644 --- a/mem/mem.go +++ b/mem/mem.go @@ -58,6 +58,8 @@ type VirtualMemoryStat struct { Slab uint64 `json:"slab"` PageTables uint64 `json:"pagetables"` SwapCached uint64 `json:"swapcached"` + CommitLimit uint64 `json:"commitlimit"` + CommittedAS uint64 `json:"committedas"` } type SwapMemoryStat struct { diff --git a/mem/mem_linux.go b/mem/mem_linux.go index fda3345..71eb654 100644 --- a/mem/mem_linux.go +++ b/mem/mem_linux.go @@ -60,6 +60,10 @@ func VirtualMemory() (*VirtualMemoryStat, error) { ret.PageTables = t * 1024 case "SwapCached": ret.SwapCached = t * 1024 + case "CommitLimit": + ret.CommitLimit = t * 1024 + case "Committed_AS": + ret.CommittedAS = t * 1024 } } if !memavail { diff --git a/mem/mem_test.go b/mem/mem_test.go index 4a1ae7b..feeb59e 100644 --- a/mem/mem_test.go +++ b/mem/mem_test.go @@ -57,7 +57,7 @@ func TestVirtualMemoryStat_String(t *testing.T) { UsedPercent: 30.1, Free: 40, } - e := `{"total":10,"available":20,"used":30,"usedPercent":30.1,"free":40,"active":0,"inactive":0,"wired":0,"buffers":0,"cached":0,"writeback":0,"dirty":0,"writebacktmp":0,"shared":0,"slab":0,"pagetables":0,"swapcached":0}` + e := `{"total":10,"available":20,"used":30,"usedPercent":30.1,"free":40,"active":0,"inactive":0,"wired":0,"buffers":0,"cached":0,"writeback":0,"dirty":0,"writebacktmp":0,"shared":0,"slab":0,"pagetables":0,"swapcached":0,"commitlimit":0,"committedas":0}` if e != fmt.Sprintf("%v", v) { t.Errorf("VirtualMemoryStat string is invalid: %v", v) }