# apache use 100% of CPU



## mfaridi (Jun 27, 2009)

we have server use FreeBSD and apache for web server and we have 130 VHOST , sometimes when I run top I see apache use 100% of CPU and and I see many httpd process is running ,
I want understand which vhost use all of my systems.
Is this possible ?
I want understand which VHOST use all of apache ?


----------



## mfaridi (Jun 27, 2009)

there is no answer ?


----------



## mk (Jun 27, 2009)

mfaridi said:
			
		

> there is no answer ?



i was just about to click to see what you answer to your self, and i thought that you will write the above sentece. and you did.
you are the system administrator right? you have to know your system better than anything else in this world - this is your sole purpose. you have a problem - you have to resolve it. as prudent administrator you write down blueprint of your system - notes of hardware, os installation and configuration, 3rd party software, any bottle necks - os itselef, hardware and those made it by 3rd parties. what are you serving - heavy web pages or light web pages? flash? or html? is this system is hammered with requests for content? et cetera..et cetera. 

and for the last - this is rude i know, dont thank me - one of my math lectors have a favourite answer to all my quiestions (i dont walk the math walk as i want to..): think before ask - this is what she says to me any time she see that i open my mouth. and she is right - 75% of the time i need minute or so to get the picture. you shoud try it 
good luck


----------



## mfaridi (Jun 27, 2009)

mk said:
			
		

> i was just about to click to see what you answer to your self, and i thought that you will write the above sentece. and you did.
> you are the system administrator right? you have to know your system better than anything else in this world - this is your sole purpose. you have a problem - you have to resolve it. as prudent administrator you write down blueprint of your system - notes of hardware, os installation and configuration, 3rd party software, any bottle necks - os itselef, hardware and those made it by 3rd parties. what are you serving - heavy web pages or light web pages? flash? or html? is this system is hammered with requests for content? et cetera..et cetera.
> 
> and for the last - this is rude i know, dont thank me - one of my math lectors have a favourite answer to all my quiestions (i dont walk the math walk as i want to..): think before ask - this is what she says to me any time she see that i open my mouth. and she is right - 75% of the time i need minute or so to get the picture. you shoud try it
> good luck



I want understand which vhost use all of apache power


----------



## DutchDaemon (Jun 27, 2009)

mfaridi said:
			
		

> there is no answer ?



I really wish you would stop doing this, Mostafa. It sounds impatient, and it sounds demanding, especially after only 7 hours.. No one has the obligation to solve your problems for you, and certainly not on such short notice. 

I'm sure you don't mean it that way, but frankly, I don't want to see 'there is no answer ?' posts again.


----------



## mfaridi (Jun 27, 2009)

DutchDaemon said:
			
		

> I really wish you would stop doing this, Mostafa. It sounds impatient, and it sounds demanding, especially after only 7 hours.. No one has the obligation to solve your problems for you, and certainly not on such short notice.
> 
> I'm sure you don't mean it that way, but frankly, I don't want to see 'there is no answer ?' posts again.



ok 
thanks
I do not do that again
but sometimes I need answer of my question quickly and it is important for me
for example this question is very important for me because I work for company and we host many sites and I want understand which vhost use all of apache. if I can not find answer this question maybe I will lose of my job

sorry again


----------



## DutchDaemon (Jun 27, 2009)

There is no way to look at e.g. 'ps ax' or 'top' and find out which particular vhost is responsible for CPU usage. The answer lies in your Apache logfiles, and statistics made from those. 

If you're logging everything to a single logfile, I suggest adding a virtual host variable to your logging statement (I think you need to define a Custom Log with %v (?) added), which logs the virtual website with every request, or giving each virtual host a separate logfile, so you can see which one grows the fastest. 

Running statistics like www/webalizer and/or www/awstats on your Apache logfiles will give you a clear insight into which sites get the most visits. 

Note that the number of visits alone may not explain the 100% CPU usage. Some sites may use sub-optimal Perl/PHP/Python/CGI scripts that lock up or cannibalise the resources on the server. Try running the most recent versions of ports, and switch off unneeded options.

Also take a close look at your Apache error logs, because they usually give info about aborted processes, or faulty scripts.


----------



## mk (Jun 27, 2009)

let start with the simple,obvious part - logs - apache,*sql,system, output of top/ps commands.
apachectl fullstatus command 
mod_status look very promising about vhost specific usage


----------

