How to find the total RAM dedicated to apache web server

apache-2.2memory

I am trying to figure how how much RAM my apache web server is currently using and how much RAM is it allowed to use.

The ps command in linux can give me the memory usage on a per child process basis:

ps aux | grep apache2
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      1130  0.0  0.1 149080 10600 ?        Ss   12:36   0:00 /usr/sbin/apache2 -k start
www-data  2051  0.0  0.3 163608 23592 ?        S    16:46   0:00 /usr/sbin/apache2 -k start
www-data  2506  0.0  0.1 149376  7952 ?        S    16:47   0:00 /usr/sbin/apache2 -k start
www-data  5149  0.0  0.1 149416  7980 ?        S    16:49   0:00 /usr/sbin/apache2 -k start
www-data  5175  0.0  0.1 149368  7876 ?        S    16:49   0:00 /usr/sbin/apache2 -k start
www-data 10212  0.0  0.1 149368  7848 ?        S    16:53   0:00 /usr/sbin/apache2 -k start
www-data 19114  0.0  0.1 149368  7904 ?        S    17:01   0:00 /usr/sbin/apache2 -k start
www-data 19138  0.0  0.1 150768 11856 ?        S    17:01   0:00 /usr/sbin/apache2 -k start
www-data 20592  0.0  0.1 149428  8092 ?        S    16:35   0:00 /usr/sbin/apache2 -k start
www-data 21336  0.0  0.1 149368  7808 ?        S    17:03   0:00 /usr/sbin/apache2 -k start
www-data 21375  0.0  0.1 149432  7916 ?        S    17:03   0:00 /usr/sbin/apache2 -k start
1000     26458  0.0  0.0   8112   896 pts/6    S+   17:07   0:00 grep apache2
www-data 30848  0.0  0.1 149396  8044 ?        S    16:43   0:00 /usr/sbin/apache2 -k start

I know how much RAM I have:

/proc $ cat meminfo
MemTotal:        6113156 kB

But what I am looking for is a figure that shows me how much RAM (memory) all the apache spawned processes collectively are using.

Best Answer

TOTAL=0;for MEM in `ps -U www-data -o rss | grep -v RSS`; do TOTAL=$(($TOTAL+$MEM)); done;echo $TOTAL
Related Topic