I need to get a memory usage in % from vmstat, but I don't quite understand some of the numbers relating to memory displayed in vmstat.
In particular, given an output like this
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 139728 45396 199128 1236360 1 2 4 622 3 1 51 4 43 2 0
What is the amount of total memory of the system? Is it 'swpd' + 'free' + 'buff' + 'cache', which total to 1620612?
What is the free amount of memory of the system? Is it 45396, as displayed in the 'free' column?
The problem is they don't add up or even look close to what 'top' reported. The output of 'top' which I took around the same time as 'vmstat's above is:
[...]
Mem: 4059616k total, 3965504k used, 94112k free, 200020k buffers
[...]
So...I am assuming there must be hidden numbers/options in 'vmstat' that I didn't know of?
I need to use 'vmstat' for this purpose and not other commands as this is what the requirement stated.
So ideally, what I want to achieve from 'vmstat' is the % memory usage, as in:
<used_memory>/<total_memory> * 100%.
Thanks!