Welcome to
LabradorData INTERNET SERVICES
Exclusive Provider of
MyWebMaker
Free : display VPS memory usage
Free is a little bash script for use on a Virtuozzo or OpenVz VPS to display the current memory usage at the command line.

#!/bin/bash
#
# Revised 02-Feb-2007: include kernel memory (kmemsize) in 'used' calculation
# and show percentages in output.
#
BEAN=`cat /proc/user_beancounters`
GUAR=`echo "$BEAN" | grep vmguar | awk '{ print $4;}'`
PRIV=`echo "$BEAN" | grep privvm | awk '{ print $2;}'`
KMEM=`echo "$BEAN" | grep kmem | awk '{ print $3;}'`
let TOTL=$GUAR/256
let KMMB=$KMEM/1048576
let PVMB=$PRIV/256
let USED=$KMMB+$PVMB
let FREE=$TOTL-$USED
if [ "$FREE" -gt "0" ]; then
let UPER=$USED*100/$TOTL
let FPER=100-$UPER
else
let UPER="100"
let FPER="0"
fi
echo "VPS Memory:"
echo " Total: $TOTL mb Used: $USED mb (${UPER}%) Free: $FREE mb (${FPER}%)"

Instructions:

  1. Copy the above code and as root paste and save it as /bin/Free
    (that's "Free" with a capital "F").
  2. Make it executable: chmod 700 /bin/Free

Try it out:

[root@vps]# Free
VPS Memory:
Total: 256 mb Used: 92 mb (35%) Free: 164 mb (65%)

Negative value for amount free:

If you see a negative value, e.g., Free: -20 mb this means you are current exceeding your allocated guaranteed memory (i.e., you're using burst memory).

Note:

On Virtuozzo v.3 or OpenVZ you can only use Free as root. If you want to use it as a non-root user you'll need to:

  1. Install the beanc helper app.
  2. Change line 6 of the Free script to:
    BEAN=`beanc`
  3. Make Free executable by everyone: chmod 755 /bin/Free
Bug reports and general comments are always welcome. Please address them to drobbinslabradordataca.

-- Doug Robbins

© 2008 LabradorData

Powered by MyWebMaker CMS

Cached · 3 MySQL queries · Generated in 0.0018 sec

Webmaster Login