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
- `.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

View file

@ -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
}