For apache2 (httpd) on debian sqeeze, but should work on almost any dist as long awk is installed
$ ps aux | grep 'apache2' | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB";}'
and for mysql
$ ps aux | grep 'mysqld' | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB";}'