From 1cd02cb77f41d4ea510d9278d22b9be19361e7bf Mon Sep 17 00:00:00 2001 From: Mitchell O'Sullivan Date: Mon, 2 May 2022 21:18:50 +1000 Subject: [PATCH] feat: add property for available memory --- docs/docs/segments/sysinfo.md | 4 +++- src/segments/sysinfo.go | 14 ++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/docs/segments/sysinfo.md b/docs/docs/segments/sysinfo.md index ac3245bb..8095f6ef 100644 --- a/docs/docs/segments/sysinfo.md +++ b/docs/docs/segments/sysinfo.md @@ -41,7 +41,9 @@ Display SysInfo. ### Properties - `.PhysicalTotalMemory`: `int` - is the total of used physical memory -- `.PhysicalFreeMemory`: `int` - is the total of free physical memory +- `.PhysicalAvailableMemory`: `int` - is the total available physical memory (i.e. the amount immediately available to processes) +- `.PhysicalFreeMemory`: `int` - is the total of free physical memory (i.e. considers memory used by the system for any reason +[e.g. caching] as occupied) - `.PhysicalPercentUsed`: `float64` - is the percentage of physical memory in usage - `.SwapTotalMemory`: `int` - is the total of used swap memory - `.SwapFreeMemory`: `int` - is the total of free swap memory diff --git a/src/segments/sysinfo.go b/src/segments/sysinfo.go index ee220acc..08209cf6 100644 --- a/src/segments/sysinfo.go +++ b/src/segments/sysinfo.go @@ -16,12 +16,13 @@ type SystemInfo struct { Precision int // mem - PhysicalTotalMemory uint64 - PhysicalFreeMemory uint64 - PhysicalPercentUsed float64 - SwapTotalMemory uint64 - SwapFreeMemory uint64 - SwapPercentUsed float64 + PhysicalTotalMemory uint64 + PhysicalAvailableMemory uint64 + PhysicalFreeMemory uint64 + PhysicalPercentUsed float64 + SwapTotalMemory uint64 + SwapFreeMemory uint64 + SwapPercentUsed float64 // cpu Times float64 CPU []cpu.InfoStat @@ -57,6 +58,7 @@ func (s *SystemInfo) Init(props properties.Properties, env environment.Environme memStat, err := mem.VirtualMemory() if err == nil { s.PhysicalTotalMemory = memStat.Total + s.PhysicalAvailableMemory = memStat.Available s.PhysicalFreeMemory = memStat.Free s.PhysicalPercentUsed = memStat.UsedPercent }