In my experience, the hardest thing to work around when using a VPS for hosting is limited memory. It’s definitely a challenge to try and tune a database, web server, and application server for load under the constraints of a VPS plan (typically 512 MB or less of RAM). The best solution I came-up with was to use a baseline of about 70% of my guaranteed memory quota when the various servers started up, with 30% of my guaranteed memory free for high traffic situations. This seems to be working for me pretty well so far, especially considering that my memory usage can theoretically temporarily burst to 300% of my guaranteed memory quota.
However hosting in a VPS can present some challenges when trying to determine load and memory usage for your VPS. For instance, when using top, the memory statistics displayed represent the whole server and not your VPS. That said, I’ve only found one way to get an idea of what my memory usage is, how much I have reserved, and how much my VPS is allowed to burst to via command line is this script:
#!/bin/bash
bean=`cat /proc/user_beancounters`
guar=`echo "$bean" | grep vmguar | awk '{ print $4;}'`
burst=`echo "$bean" | grep privvm | awk '{ print $5;}'`
priv=`echo "$bean" | grep privvm | awk '{ print $2;}'`
let total=guar/256
let used=priv/256
let burst=burst/256
echo "VPS memory usage:"
echo "Used: $used MB"
echo "Total: $total MB"
echo "Burstable to: $burst MB"
As far as I know this should work under any Virtuozzo Linux based virtual private server.



1 person has left a comment
try this:
NUM=0 && for num in $( ps axo %mem | grep -v "%MEM" | grep -v "0.0" | sed 's/\.//' | sed 's/0//' ) ; do NUM=$[ $num + $NUM ];done; free=$(free -m| grep "Mem:" | awk '{fs=" "; print $2}') ;usedmem=$[ $free * $NUM / 1000 ];echo -e "\nSystem Memory Report:\nTotal on Server: $free"MB" - Used: $usedmem"MB"\n"