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:
Create the directory ~/bin, then save the above code as "vmem" inside that directory and "chmod +x ~/bin/vmem" to make it executable. Now edit your ~/.bashrc, and add "~/bin/vmem" at the end, thus you'll get a memory report every time you login, or every time you type "vmem" in the shell.Code:#!/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}%)"
v5 - New: Better display of requested memory usage
v4 - New: check for VPS, clean code, comments
v3 - New: adds 'bustable' & 'requested' memory...
v2 - New: adds 'free' memory and percentages...


LinkBack URL
About LinkBacks



Reply With Quote



Bookmarks