OpenVZ vm Server Memory Usage (script)

Here one can find interesting information about OpenVZ management and maintenance. OpenVZ control panels information also goes here

OpenVZ vm Server Memory Usage (script)

Postby lik » Tue May 12, 2009 3:00 am

Server Memory Usage (script)

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"
lik
Founder
Founder
 
Posts: 497
Joined: Wed Dec 15, 2010 3:21 am

Return to OpenVZ related

 


  • Related topics
    Replies
    Views
    Last post
cron