-   Linux - Server (
-   -   How to find total apache memory usage? (

j0hnsmith 09-12-2010 10:17 PM

How to find total apache memory usage?
Top only show the memory usage for individual processes. Apache often runs hundreds of processes, each of which may use only a small amount of memory, however the total memory consumed by all apache processes can be fairly large.

Is there a way to see the total memory usage for all apache processes?

gilead 09-12-2010 10:49 PM

Are you familiar with perl? The info here might help if you are.

j0hnsmith 09-13-2010 01:31 AM

I am familiar with perl but don't use it myself (I'm a python man), that script looks cool though. I tried to run it and got an error related to `use Statistics::Descriptive;`, a module I don't have I assume.

syg00 09-13-2010 02:04 AM

Wellll .... in that case, try this.
Much better - handles shared libraries.

ghostdog74 09-13-2010 02:05 AM


ps aux| awk '/apach[e]/{total+=$4}END{print total}'

j0hnsmith 09-13-2010 02:26 AM

Using the python script recommended by syg00 I get

Private  +  Shared  =  RAM used        Program

252.0 KiB +  89.0 KiB = 341.0 KiB        fishd
476.0 KiB + 120.5 KiB = 596.5 KiB        memcached
696.0 KiB + 124.0 KiB = 820.0 KiB        init
  1.1 MiB + 188.0 KiB =  1.3 MiB        fish
960.0 KiB + 681.0 KiB =  1.6 MiB        nginx (2)
  1.8 MiB + 711.5 KiB =  2.5 MiB        sshd (2)
  3.6 MiB +  2.3 MiB =  5.8 MiB        postgres (5)
 32.7 MiB +  5.5 MiB =  38.3 MiB        apache2 (4)
                        51.2 MiB

However top shows about 250mb total memory used, so the majority is unaccounted for.

syg00 09-13-2010 02:41 AM

That is because the script takes into account the (common) shared libraries that most utilities count multiple times.
Memory accounting is a real can of worms - try looking at this for example.

j0hnsmith 09-13-2010 03:49 AM


Originally Posted by syg00 (Post 4095768)
Memory accounting is a real can of worms - try looking at this for example.

Indeed. I was hoping there was an easy way to get the number that accounts for the difference between total memory used when apache is and isn't running, without stopping apache. Seems that top > stop apache > top > start apache is the only 'real' way.

Thanks for all your replies.

All times are GMT -5. The time now is 07:41 AM.