feat: add property for available memory

This commit is contained in:
Mitchell O'Sullivan 2022-05-02 21:18:50 +10:00 committed by Jan De Dobbeleer
parent 3fc13f7893
commit 1cd02cb77f
2 changed files with 11 additions and 7 deletions

View file

@ -41,7 +41,9 @@ Display SysInfo.
### Properties ### Properties
- `.PhysicalTotalMemory`: `int` - is the total of used physical memory - `.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 - `.PhysicalPercentUsed`: `float64` - is the percentage of physical memory in usage
- `.SwapTotalMemory`: `int` - is the total of used swap memory - `.SwapTotalMemory`: `int` - is the total of used swap memory
- `.SwapFreeMemory`: `int` - is the total of free swap memory - `.SwapFreeMemory`: `int` - is the total of free swap memory

View file

@ -17,6 +17,7 @@ type SystemInfo struct {
Precision int Precision int
// mem // mem
PhysicalTotalMemory uint64 PhysicalTotalMemory uint64
PhysicalAvailableMemory uint64
PhysicalFreeMemory uint64 PhysicalFreeMemory uint64
PhysicalPercentUsed float64 PhysicalPercentUsed float64
SwapTotalMemory uint64 SwapTotalMemory uint64
@ -57,6 +58,7 @@ func (s *SystemInfo) Init(props properties.Properties, env environment.Environme
memStat, err := mem.VirtualMemory() memStat, err := mem.VirtualMemory()
if err == nil { if err == nil {
s.PhysicalTotalMemory = memStat.Total s.PhysicalTotalMemory = memStat.Total
s.PhysicalAvailableMemory = memStat.Available
s.PhysicalFreeMemory = memStat.Free s.PhysicalFreeMemory = memStat.Free
s.PhysicalPercentUsed = memStat.UsedPercent s.PhysicalPercentUsed = memStat.UsedPercent
} }