Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

TOTAL=0;for MEM in `ps -U www-data -o rss | grep -v RSS`; do TOTAL=$(($TOTAL+$MEM)); done;echo $TOTAL
share|improve this answer
    
I dont think ps is an accurate program because it calculates resident memory and virtual memory INCLUDING shared libraries. I think pmap would be more effective. –  JohnMerlino Jul 13 '13 at 17:38

Have a look at the check-httpd-limits project, from the project's page:

check_httpd_limits.pl compares the size of running Apache httpd processes, the configured prefork / worker / event MPM limits, and the server's available memory. The script exits with a warning (or error message) if the configured limits exceed the server's available memory.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.