PDA

View Full Version : Application monitoring: apache


Juan Carlos
25-04-2006, 18:04
Hi All,

I want to share my little script to monitor apache performance:

your have to create your "UserParameter" in /etc/zabbix/zabbix_agentd.conf"

UserParameter=apache.total_accesses,/usr/local/ackstorm/zabbix_agentd/ack_zabbix_apache.pl|cut -f1 -d":"
UserParameter=apache.total_kbytes,/usr/local/ackstorm/zabbix_agentd/ack_zabbix_apache.pl|cut -f2 -d":"
UserParameter=apache.cpuload,/usr/local/ackstorm/zabbix_agentd/ack_zabbix_apache.pl|cut -f3 -d":"
UserParameter=apache.uptime,/usr/local/ackstorm/zabbix_agentd/ack_zabbix_apache.pl|cut -f4 -d":"
UserParameter=apache.reqpersec,/usr/local/ackstorm/zabbix_agentd/ack_zabbix_apache.pl|cut -f5 -d":"
UserParameter=apache.bytespersec,/usr/local/ackstorm/zabbix_agentd/ack_zabbix_apache.pl|cut -f6 -d":"
UserParameter=apache.bytesperreq,/usr/local/ackstorm/zabbix_agentd/ack_zabbix_apache.pl|cut -f7 -d":"
UserParameter=apache.busyservers,/usr/local/ackstorm/zabbix_agentd/ack_zabbix_apache.pl|cut -f8 -d":"
UserParameter=apache.idleservers,/usr/local/ackstorm/zabbix_agentd/ack_zabbix_apache.pl|cut -f9 -d":"

source code for "ack_zabbix_apache.pl" is:

#!/usr/bin/perl

# Debian Users: apt-get install libwww-perl

use LWP::Simple;
use strict;

my($url)="http://localhost/server-status?auto";
my($server_status)=get($url);
my($total_accesses,$total_kbytes,$cpuload,$uptime, $reqpersec,$bytespersec,$bytesperreq,$busyservers, $idleservers);

if (! $server_status) {
print "Can't access $url\nCheck apache configuration\n\n";
exit(1);
}

$total_accesses = $1 if ($server_status =~ /Total\ Accesses:\ ([\d|\.]+)/ig)||0;
$total_kbytes = $1 if ($server_status =~ /Total\ kBytes:\ ([\d|\.]+)/gi);
$cpuload = $1 if ($server_status =~ /CPULoad:\ ([\d|\.]+)/gi);
$uptime = $1 if ($server_status =~ /Uptime:\ ([\d|\.]+)/gi);
$reqpersec = $1 if ($server_status =~ /ReqPerSec:\ ([\d|\.]+)/gi);
$bytespersec = $1 if ($server_status =~ /BytesPerSec:\ ([\d|\.]+)/gi);
$bytesperreq = $1 if ($server_status =~ /BytesPerReq:\ ([\d|\.]+)/gi);
$busyservers = $1 if ($server_status =~ /BusyServers:\ ([\d|\.]+)/gi);
$idleservers = $1 if ($server_status =~ /IdleServers:\ ([\d|\.]+)/gi);

printf "%i:%i:%.2f:%i:%.2f:%.2f:%.2f:%i:%i\n",$total_accesses,$total_kbytes,$cpuload,$uptime,$r eqpersec,$bytespersec,$bytesperreq,$busyservers,$i dleservers;
exit(0);

elkor
26-04-2006, 16:37
You have two erroneous spaces in the printf statement, other than that looks good.

thanks for contributing!

Juan Carlos
28-04-2006, 02:20
I see...
Copy and paste problem... :(

printf "%i:%i:%.2f:%i:%.2f:%.2f:%.2f:%i:%i\n",$total_accesses,$total_kbytes,$cpuload,$uptime,$r eqpersec,$bytespersec,$bytesperreq,$busyservers,$i dleservers;

linuxman
12-07-2006, 00:07
Hi Juan Carlos
When i test your code by
perl ack_zabbix_apache.pl
this error occured
Can't locate LWP/Simple.pm in @INC (@INC contains:
/usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5
/usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3
/usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5
/usr/lib/perl5/vendor_perl/5.8.4 /usr/lib/perl5/vendor_perl/5.8.3
/usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/5.8.6 .) at /root/ack_zabbix_apache.pl line 5
--There are perl package that installed on server:-
perl-Filter-1.30-7
perl-URI-1.35-2
perl-5.8.6-24
perl-DBD-MySQL-2.9007-1
perl-DBI-1.48-4
--Server Specs
Linux Fedora 4
Kernel 2.6.17-1.2139_FC4smp
Apache version: Apache/2.0.54
____________
Best Regards;

linuxman
12-07-2006, 01:06
Hi
I found that i loss LWB::Simple module so i download
http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/libwww-perl-5.805.tar.gz
then install
perl Makefile.PL ; make ; make test ; make install
all run OK exept make is generate this error
Failed 10/30 test scripts, 66.67% okay. 168/799 subtests failed, 78.97% okay.
make: *** [test] Error 255
--But also i couldn't run script
this error occured
Bareword found where operator expected at ack_zabbix_apache.pl line 27, near "$r eqpersec"
(Missing operator before eqpersec?)
Bareword found where operator expected at ack_zabbix_apache.pl line 27, near "$i dleservers"
(Missing operator before dleservers?)
Global symbol "$r" requires explicit package name at ack_zabbix_apache.pl line 27.
syntax error at ack_zabbix_apache.pl line 27, near "$r eqpersec"
Global symbol "$i" requires explicit package name at ack_zabbix_apache.pl line 27.
Execution of ack_zabbix_apache.pl aborted due to compilation errors.

linuxman
12-07-2006, 01:40
elhamdulilah all problem solved,
but when i runing it invok

Can't access http://localhost/server-status?auto
Check apache configuration

yes i havn't server-status file because i don't know containts of this file :confused: ?!

Klug
12-07-2006, 09:53
yes i havn't server-status file because i don't know containts of this file :confused: ?!
It's not a file.

Read the httpd.conf of the apache instance you want to monitor, you'll find all the needed informations within (what is /server-status, how to activate it, etc).

Here's the doc for apache2 : http://httpd.apache.org/docs/2.0/mod/mod_status.html