Apache Mod_Watch & Munin Graphs showing vhost accesses
While this is more of an apache topic than a munin one, the main reason I wanted to compile the mod_watch module for apache is so I can graph vhost usage and access. Munin will then show graphs of how much a vhost is used. Also, while there are other how-to websites out there for this, they seem to drop off and disappear after a few years.
mod_watch itself is not supported and is actually quite difficult to get a hold of. I was using this on Debian Etch and Lenny on a x32 system. Copying the mod_watch.so and running on x64 failed so I needed to recomiple on a x64 debian squeeze.
The main reference I used was: http://stubbedtoe.co.nz/index.php/2009/09/apache-vhost-monitoring-with-munin/ This worked perfectly. There was an issue with debian squeeze which will be sorted below.
Compile
apt-get install apache2-dev libcrypt-ssleay-perl libwww-perl make wget http://wiki.kartbuilding.net/mod_watch-4.3_apache22_mod.tar.gz #gunzip and tar -xvf nano Makefile.dso //change APXS location to: APXS=/usr/bin/apxs2 make -f Makefile.dso build make -f Makefile.dso install
Add and config mod_watch apache module
vi /etc/apache2/mods-available/watch.load
//add in
LoadModule watch_module /usr/lib/apache2/modules/mod_watch.so
a2enmod watch
vi /etc/apache2/sites-enabled/01-default (or whatever vhost you want)
<Location /watch-info>
SetHandler watch-info
Order deny,allow
Deny from all
Allow from 127.0.0.1 ::1
</Location>
<Location /watch-list>
SetHandler watch-list
Order deny,allow
Deny from all
Allow from 127.0.0.1 ::1
</Location>
/etc/init.d/apache2 restart
Checking mod_watch for errors
elinks http://localhost/watch-list #check for output
mod_watch Errors received
in error.log with Debian Squeeze running 2.6.32-5-amd64
tail -f /var/log/apache2/error.log //I noticed the following warns when I accessed any vhosts with mod_watch enabled [Fri Mar 18 22:35:36 2011] [crit] (20014)Internal error: shGetLockedEntry(7fca84e5aae8, "SERVER") failed in watchPostReadRequestHash() [Fri Mar 18 22:35:36 2011] [error] shVerifyString(7fca84e5aae8, 7fca83c946f8) failed! [Fri Mar 18 22:35:36 2011] [crit] (20014)Internal error: shGetLockedEntry(7fca84e5aae8, "monitor2.burkesys.com") failed in watchLogHash() [Fri Mar 18 22:35:36 2011] [error] shVerifyString(7fca84e5aae8, 7fca83c94718) failed! [Fri Mar 18 22:35:36 2011] [crit] (20014)Internal error: shGetLockedEntry(7fca84e5aae8, "SERVER") failed in watchLogHash()
resolve mod_watch errors
Googling led me to http://forums.cacti.net/viewtopic.php?p=186639#p186639
cd /root/mod_watch-4.3_apache22_mod/
vi SharedHash.c
//on line 102 change to look like:
shVerifyString(struct shTable *tp, char *str)
{
/* if ((char *) tp->shared <= str && str < (char *) tp->eshared) { */
if ((char *) apr_shm_baseaddr_get(tp->shared) <= str && str < (char *) tp->eshared) {
if (str + strlen(str) < (char *) tp->eshared)
return str;
}
So now browing various vhosts on the server showed no errors in error.log. Using elinks (apt-get install elinks) going to http://localhost/watch-list showed results.
Munin Plugin for Mod_Watch
cd /usr/share/munin/plugins wget http://wiki.kartbuilding.net/apache_watch chmod 755 apache_watch vi apache_watch //change my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://monitor2.burkesys.com:%d/watch-list"; to: my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://server.com:%d/watch-list"; ln -s /usr/share/munin/plugins/apache_watch /etc/munin/plugins/apache_watch_requests
That should do it. Once mod_watch is working and accessible munin should pick it up ok. References: http://stubbedtoe.co.nz/index.php/2009/09/apache-vhost-monitoring-with-munin/
http://exchange.munin-monitoring.org/plugins/apache_watch_/version/1
http://forums.cacti.net/about15475.html
This is a nice apache module. I'm surprised that there is no maintained similar apache module. I've seen another similar munin plugin that parses /var/log/apache2/vhost%_access.log to generate these graphs, however it requires separate log files for each vhost and parses the logs every so often. Any more info /queries / suggestions drop us a mail sburke[at]burkesys.com
'리눅스 > 어플리케이션' 카테고리의 다른 글
| [Apache] mod_watch backup (0) | 2011/08/20 |
|---|---|
| [MRTG] 자동 설치 스크립트 (0) | 2011/08/16 |
| [작성중] CentOS 5.6 APM Compile (0) | 2011/08/14 |
| [PHP] x86_64 에서 PHP MSSQL 모듈 설치시, libsybdb.a|so 오류 (0) | 2011/01/10 |
| [Apache] 컴파일한 httpd를 chkconfig 로 등록하기. (2) | 2011/01/01 |
| [PHP][작성중] CentOS PHP 컴파일 (3) | 2010/12/24 |

