From 4e543bbae2321bb600ad59a331867a4b09747248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Mei=C3=9Fner?= Date: Sun, 18 Apr 2021 15:18:24 +0200 Subject: [PATCH 1/2] Read more values from /proc/meminfo on Linux. --- memory/memory_linux.go | 11 ++++++++++- memory/memory_linux_test.go | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/memory/memory_linux.go b/memory/memory_linux.go index 5b5a0df..3276621 100644 --- a/memory/memory_linux.go +++ b/memory/memory_linux.go @@ -25,7 +25,8 @@ func Get() (*Stats, error) { // Stats represents memory statistics for linux type Stats struct { Total, Used, Buffers, Cached, Free, Available, Active, Inactive, - SwapTotal, SwapUsed, SwapCached, SwapFree uint64 + SwapTotal, SwapUsed, SwapCached, SwapFree, Mapped, Shmem, Slab, + PageTables, Committed, VmallocUsed, User uint64 MemAvailableEnabled bool } @@ -43,6 +44,12 @@ func collectMemoryStats(out io.Reader) (*Stats, error) { "SwapCached": &memory.SwapCached, "SwapTotal": &memory.SwapTotal, "SwapFree": &memory.SwapFree, + "Mapped": &memory.Mapped, + "Shmem": &memory.Shmem, + "Slab": &memory.Slab, + "PageTables": &memory.PageTables, + "Committed_AS": &memory.Committed, + "VmallocUsed": &memory.VmallocUsed, } for scanner.Scan() { line := scanner.Text() @@ -73,5 +80,7 @@ func collectMemoryStats(out io.Reader) (*Stats, error) { memory.Used = memory.Total - memory.Free - memory.Buffers - memory.Cached } + memory.User = memory.Total - memory.Free - memory.Buffers - memory.Cached - memory.Slab - memory.PageTables - memory.SwapCached + return &memory, nil } diff --git a/memory/memory_linux_test.go b/memory/memory_linux_test.go index 7ea4471..ec70ca1 100644 --- a/memory/memory_linux_test.go +++ b/memory/memory_linux_test.go @@ -86,6 +86,13 @@ DirectMap2M: 888832 kB SwapUsed: uint64(2432 * 1024), SwapCached: uint64(504 * 1024), SwapFree: uint64(1957500 * 1024), + Mapped: uint64(151408 * 1024), + Shmem: uint64(163548 * 1024), + Slab: uint64(202768 * 1024), + PageTables: uint64(15944 * 1024), + Committed: uint64(7238800 * 1024), + VmallocUsed: uint64(16344 * 1024), + User: uint64(1079228 * 1024), MemAvailableEnabled: false, }, }, @@ -152,6 +159,13 @@ DirectMap2M: 888832 kB SwapUsed: uint64(2432 * 1024), SwapCached: uint64(504 * 1024), SwapFree: uint64(1957500 * 1024), + Mapped: uint64(151408 * 1024), + Shmem: uint64(163548 * 1024), + Slab: uint64(202768 * 1024), + PageTables: uint64(15944 * 1024), + Committed: uint64(7238800 * 1024), + VmallocUsed: uint64(16344 * 1024), + User: uint64(1079228 * 1024), MemAvailableEnabled: true, }, }, From b349d18008f26aa1a72d92b47ec093f4a853ed4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Mei=C3=9Fner?= Date: Tue, 27 Apr 2021 15:30:10 +0200 Subject: [PATCH 2/2] Omit calculation of user space memory. --- memory/memory_linux.go | 4 +--- memory/memory_linux_test.go | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/memory/memory_linux.go b/memory/memory_linux.go index 3276621..76ca113 100644 --- a/memory/memory_linux.go +++ b/memory/memory_linux.go @@ -26,7 +26,7 @@ func Get() (*Stats, error) { type Stats struct { Total, Used, Buffers, Cached, Free, Available, Active, Inactive, SwapTotal, SwapUsed, SwapCached, SwapFree, Mapped, Shmem, Slab, - PageTables, Committed, VmallocUsed, User uint64 + PageTables, Committed, VmallocUsed uint64 MemAvailableEnabled bool } @@ -80,7 +80,5 @@ func collectMemoryStats(out io.Reader) (*Stats, error) { memory.Used = memory.Total - memory.Free - memory.Buffers - memory.Cached } - memory.User = memory.Total - memory.Free - memory.Buffers - memory.Cached - memory.Slab - memory.PageTables - memory.SwapCached - return &memory, nil } diff --git a/memory/memory_linux_test.go b/memory/memory_linux_test.go index ec70ca1..59fa193 100644 --- a/memory/memory_linux_test.go +++ b/memory/memory_linux_test.go @@ -92,7 +92,6 @@ DirectMap2M: 888832 kB PageTables: uint64(15944 * 1024), Committed: uint64(7238800 * 1024), VmallocUsed: uint64(16344 * 1024), - User: uint64(1079228 * 1024), MemAvailableEnabled: false, }, }, @@ -165,7 +164,6 @@ DirectMap2M: 888832 kB PageTables: uint64(15944 * 1024), Committed: uint64(7238800 * 1024), VmallocUsed: uint64(16344 * 1024), - User: uint64(1079228 * 1024), MemAvailableEnabled: true, }, },