Ever wondered how much memory you are currently using and how close you are to the QoS hard limit?
Here is a simple script that calculates the QoS hard memory limit and the current memory usage:
- Code: Select all
#!/bin/sh
# Make sure we are running under a VPS system with QoS
if [ ! -f "/proc/user_beancounters" ]; then
echo "File \"/proc/user_beancounters\" does not exist. Make sure this script runs on a VPS system with QoS enabled."
exit $E_NOFILE
fi
# Get memory related variables
let GMEM=`grep vmguarpages /proc/user_beancounters | awk '{print$4}'`/1024*4
let BRST=`grep privvmpages /proc/user_beancounters | awk '{print$5}'`/1024*4
let CMEM=`grep physpages /proc/user_beancounters | awk '{print$2}'`/1024*4
let REQM=`grep privvmpages /proc/user_beancounters | awk '{print$2}'`/1024*4
let FREE=$GMEM-$CMEM
# Calculate free memory
if [ "$FREE" -gt "0" ]; then
let CMEMP=$CMEM*100/$GMEM
let FREEP=100-$CMEMP
else
let CMEMP="100"
let FREEP="0"
fi
let REQMP=$REQM*100/$GMEM
# Calculate pretty output
if [ ${#CMEM} -gt ${#FREE} ]; then
let LIMIT=${#CMEM}-${#FREE}
SPACE=''
while [ $LIMIT -gt 0 ]; do
SPACE=" $SPACE"
LIMIT=`expr $LIMIT - 1`
done
else
SPACE=''
fi
# Echo results
echo "Memory limit...: $GMEM MB (burstable: $BRST MB)"
echo "Requested......: $REQM MB (${REQMP}%)"
echo "Current usage..: $CMEM MB (${CMEMP}%)"
echo "Free memory....: $FREE MB ${SPACE}(${FREEP}%)"
This one will display free memory:
- Code: Select all
#!/bin/sh
let GMEM=`grep vmguarpages /proc/user_beancounters | awk '{print$4}'`/1024*4
let CMEM=`grep physpages /proc/user_beancounters | awk '{print$2}'`/1024*4
let FMEM=$GMEM-$CMEM
echo "Memory limit...: $GMEM MB"
echo "Current usage..: $CMEM MB"
echo "Free memory..: $FMEM MB"