Ad Widget

Collapse

Application monitoring: apache

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Juan Carlos
    Junior Member
    • Apr 2006
    • 7

    #1

    Application monitoring: apache

    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_acce sses,$total_kbytes,$cpuload,$uptime,$reqpersec,$by tespersec,$bytesperreq,$busyservers,$idleservers;
    exit(0);
  • elkor
    Senior Member
    • Jul 2005
    • 299

    #2
    You have two erroneous spaces in the printf statement, other than that looks good.

    thanks for contributing!

    Comment

    • Juan Carlos
      Junior Member
      • Apr 2006
      • 7

      #3
      I see...
      Copy and paste problem...

      printf "%i:%i:%.2f:%i:%.2f:%.2f:%.2f:%i:%i\n",$total_acce sses,$total_kbytes,$cpuload,$uptime,$reqpersec,$by tespersec,$bytesperreq,$busyservers,$idleservers;

      Comment

      • linuxman
        Junior Member
        • Jul 2006
        • 3

        #4
        Error occured

        Hi Juan Carlos
        When i test your code by
        HTML Code:
        perl ack_zabbix_apache.pl
        this error occured
        Code:
        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;

        Comment

        • linuxman
          Junior Member
          • Jul 2006
          • 3

          #5
          Install missing perl module

          Hi
          I found that i loss LWB::Simple module so i download

          then install
          perl Makefile.PL ; make ; make test ; make install
          all run OK exept make is generate this error
          HTML Code:
          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.

          Comment

          • linuxman
            Junior Member
            • Jul 2006
            • 3

            #6
            Server-Status not found

            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 ?!
            Last edited by linuxman; 12-07-2006, 06:40. Reason: Check spilling

            Comment

            • Klug
              Junior Member
              • Jul 2006
              • 11

              #7
              Originally posted by linuxman
              yes i havn't server-status file because i don't know containts of this file ?!
              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

              Comment

              Working...