Sylvestre's blog

Monitoring a specific virtualhost apache

· Sly · Administration

Monitoring apache quite easy. There are plenty of solutions to do that. When it comes to monitore virtualhost one by one, it starts to be difficult. Of course, there is always the solution of using stats softwares but usually, it is not really time and doesn't give a quick and efficient overview.


Here comes mod_watch. A quite old module for Apache (1.3 & 2.0). Basically it monitores the incoming/outcoming traffic and the requests.


There is no debian package for this module. However, it is very easy to install.


apt-get install apache-dev

tar -zxvf mod_watch318.tgz
cd mod_watch-3.18

make install




Edit /etc/apache/modules.conf
And add in it :


LoadModule watch_module /usr/lib/apache/1.3/mod_watch.so




Edit /etc/apache/httpd.conf
Add :


<IfModule mod_watch.c>

# Allows the URL used to query virtual host data:
#

# http://www.snert.com/watch-info
#

<location /watch-info>
SetHandler watch-info

Order allow,deny
Allow from hostname

</location>



# Intended for debugging and analysis of shared memory

# hash table and weenie files:
#

# http://www.snert.com/watch-table
#

<location /watch-table>
SetHandler watch-table

Order allow,deny
Allow from hostname

</location>


</IfModule>




Stop & start apache (not a restart)


/etc/init.d/apache stop && /etc/init.d/apache start







For each virtualhost, you should be able to see a line containting this kind of data :
sylvestre.ledru.info 49 0 499775 39 9 1 0.000 136656176 3221223448


This means :












sylvestre.ledru.infotarget name
49uptime in second
bytes received from requests
499775bytes sent
39number of requests received
9number of documents sent
1number of active connections
0.000approx. 5 minutes average of bytes sent per second
136656176bytes sent during the current 5 minutes period
3221223448start time() of the current 5 minutes period




This data are meant to be retrieve by MRTG thought the mod_watch client in order to produce graphs, ie :


# ./mod_watch.pl http://sylvestre.ledru.info/watch-info

0
2012653

11.31
sylvestre.ledru.info


This returns the number of bytes out.

Or


# ./mod_watch.pl -f ifRequests,ifDocuments http://sylvestre.ledru.info/watch-info

241
80

13.02
sylvestre.ledru.info


This returns the number of requests and documents.


Finally, as the developer knows that ITs are lazy, he made a script which will automatically create an MRTG configuration file from the apache configuration (I made a small patch in order to monitore also the documents/requests with this script and fixes a bug with mrtg indexmaker)


wget http://sylvestre.ledru.info/howto/mod_watch/patch_apache2mrtg.diff

patch < patch_apache2mrtg.diff
Add Workdir: /path/to/www/ for the output dir

./apache2mrtg.pl /etc/apache/httpd.conf > /etc/vhosts_mrtg.cfg


Caution ! apache2mrtg.pl will parse ALL the virtualhost. Even those with htaccess login/password and then won't be able to access to the watch-info files. Remove them from the vhosts_mrtg.cfg file.


There is many solution to customize the value & data. Check out the documentation here : http://www.snert.com/Software/mod_watch/.


Advantages :

* Quite easy to install, configure & maintain
* Quite fast

* Make very easy the task to find which virtualhost takes all the bandwith.


Disavantages :
* Impact on the performance ?

* No monitoring of CPU / Memory
* Based on headers (ie, if I start a download of 200 mo and I stop at the beginning, it will count 200 mo... Problem Described here)


Next tasks :

* Patch the software to add CPU & Memory monitoring PER virtualhost or find a module which does that.
* Find a way to fix the headers issue.

* Add the total bytes transferts


Edit : Comments closed. Thank you spammers !