Strato V-Server/Virtuozzo: Memory usage

This blog runs on a virtual server offered by Strato. They use Virtuozzo for virtualization which has a drawback: If you use top, free or other tools to show the current memory usage, not only your “slice” of the machine but more (all?) of the memory is measured. This doesn’t help much if you try to find out how much of it your own processes use, which is important as you can use only a certain part of the machine’s memory.

I could not find a better way to circumvent this but to sum up the numbers of every single process, listed by ps. Here’s a little shell script that does the job:

#!/bin/bash
echo -ne "Allocated virtual memory: "
ps auxh | sed 's/ \+/ /g' | cut -d' ' -f 5 | \
php -r '$c=0; while($line=fgets(STDIN)) $c+=intval($line); echo "$c";'
echo " kB"

echo -ne "Used physical memory: "
ps auxh | sed 's/ \+/ /g' | cut -d' ' -f 6 | \
php -r '$c=0; while($line=fgets(STDIN)) $c+=intval($line); echo "$c";'
echo " kB"

You need to have the command line version of PHP 5 installed to run this script. The corresponding Debian package is called php5-cli.

Leave a Reply

Your email address will not be published. Required fields are marked *