First, the question: I need to find how much total memory is in use, give or take a megabyte, on a Linux system - CentOS but any general solution should work. I'm thinking I want to parse ps aux somehow, but adding up VSZ RSS doesn't work.
Now, for the "why are you handicapping yourself" explanation, if you care...
I'm inside an OpenVZ container. Normally, free -m or cat /proc/meminfo works fine, but the host OS has a bug. The provider doesn't want to take all the containers down to patch, so I have to live with it for a while. Unfortunately, if I reboot the VPS, I have to open a ticket to have the counters reset, otherwise it looks to me like my VPS has 10GB of RAM, an that includes meminfo and free. This week, naturally, I'm doing various tests and rebooting.
The VPS really only has 1GB/2GB burst. If all is well, I see 2048M available and free -m output is normal.
I really need to find a solution that shows the correct memory in use without relying on proc...if such a thing is possible.