Ad Widget

Collapse

Apache Monitoring for FreeBSD

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • monsieurcanard
    Member
    • Mar 2007
    • 40

    #1

    Apache Monitoring for FreeBSD

    I'm quite a fan of one-liners, so here's my UserParameters for monitoring Apache on FreeBSD:

    Code:
    UserParameter=apache.accesses,fetch -qo - http://localhost/server-status?auto | head -n 9 | grep Accesses | cut -d " " -f 3
    UserParameter=apache.totalkb,fetch -qo - http://localhost/server-status?auto | head -n 9 | grep kBytes | cut -d " " -f 3
    UserParameter=apache.cpuload,fetch -qo - http://localhost/server-status?auto | head -n 9 | grep CPULoad | cut -d " " -f 2
    UserParameter=apache.uptime,fetch -qo - http://localhost/server-status?auto | head -n 9 | grep Uptime | cut -d " " -f 2
    UserParameter=apache.reqpersec,fetch -qo - http://localhost/server-status?auto | head -n 9 | grep ReqPerSec | cut -d " " -f 2
    UserParameter=apache.bytespersec,fetch -qo - http://localhost/server-status?auto | head -n 9 | grep BytesPerSec | cut -d " " -f 2
    UserParameter=apache.bytesperreq,fetch -qo - http://localhost/server-status?auto | head -n 9 | grep BytesPerReq | cut -d " " -f 2
    UserParameter=apache.busywokers,fetch -qo - http://localhost/server-status?auto | head -n 9 | grep BusyWorkers | cut -d " " -f 2
    UserParameter=apache.idleworkers,fetch -qo - http://localhost/server-status?auto | head -n 9 | grep IdleWorkers | cut -d " " -f 2
    Hope that helps!
    Matt :-)
    Last edited by monsieurcanard; 14-04-2007, 19:57.
  • crashdummyMCH
    Member
    • Jun 2006
    • 33

    #2
    Apache monitoring 1 check send all data points

    --zabbix node--
    1. edit /etc/zabbix/zabbix_agentd.conf
    add the control script as a UserParameter
    #apache server status
    UserParameter=apache.all,/usr/local/zabbix_agentd/apache.pl http://localhost

    2. copy the attached apache.txt to /usr/local/zabbix_agentd/apache.pl
    3. copy the attached zabbix_sender.txt to /usr/local/zabbix_agentd/zabbix_sender.sh

    4. Configure httpd.conf to allow server-status page from localhost

    What this will allow is for the appache.pl to pull all data points and then send them off to the server while only loading the server-status page once
    --zabbix node--

    --zabbix web--
    1. create item apache controller
    type=zabbix agent (active)
    key=apache.all
    type of information=numeric
    2. create items for each data point pulled from apache.pl
    type=zabbix trapper
    key=apache.busyservers
    type of information=numeric
    -note repeat this step for all of the points collected by apache.pl MATCH THE KEY NAME EXACTLY
    --zabbix web--

    After all of this you should now start to see data come in for all of your data points. The advantage to this is that the host only hits the server-status page once guaranteeing that all of the data points are for the same time period.

    Hope this helps.
    Attached Files

    Comment

    • bashman
      Senior Member
      • Dec 2009
      • 432

      #3


      I use this script for monitoring apache:

      Code:
       ./zapache -h
      
        zapache version: 1.0
        usage:
          ./zapache TotalAccesses               -- Check total accesses.
          ./zapache TotalKBytes                 -- Check total KBytes.
          ./zapache Uptime                      -- Check uptime.
          ./zapache ReqPerSec                   -- Check requests per second.
          ./zapache BytesPerSec                 -- Check Bytes per second.
          ./zapache BytesPerReq                 -- Check Bytes per request.
          ./zapache BusyWorkers                 -- Check busy workers.
          ./zapache IdleWorkers                 -- Check idle workers.
          ./zapache version                     -- Version of this script.
      Code:
      #! /bin/bash
      #
      # Name: zapache
      #
      # Checks Apache activity.
      #
      # Author: bashman
      #
      # Version: 1.0 21/03/10
      #
      
      zapachever="1.0"
      rval=0
      REFRESH=$(wget --quiet -O /home/zabbix/apache_status http://localhost/server-status?auto)
      
      case $1 in
      'TotalAccesses')
              $REFRESH
              grep "Total Accesses:" /home/zabbix/apache_status|awk '{print $3}'
              rval=$?;;
      'TotalKBytes')
              $REFRESH
              grep "Total kBytes:" /home/zabbix/apache_status|awk '{print $3}'
              rval=$?;;
      'Uptime')
              $REFRESH
              grep "Uptime:" /home/zabbix/apache_status|awk '{print $2}'
              rval=$?;;
      'ReqPerSec')
              $REFRESH
              grep "ReqPerSec:" /home/zabbix/apache_status|awk '{print $2}'
              rval=$?;;
      'BytesPerSec')
              $REFRESH
              grep "BytesPerSec:" /home/zabbix/apache_status|awk '{print $2}'
              rval=$?;;
      'BytesPerReq')
              $REFRESH
              grep "BytesPerReq:" /home/zabbix/apache_status|awk '{print $2}'
              rval=$?;;
      'BusyWorkers')
              $REFRESH
              grep "BusyWorkers:" /home/zabbix/apache_status|awk '{print $2}'
              rval=$?;;
      'IdleWorkers')
              $REFRESH
              grep "IdleWorkers:" /home/zabbix/apache_status|awk '{print $2}'
              rval=$?;;
      'version')
              echo "$zapachever"
              exit $rval;;
      *)
              echo "zapache version: $zapachever"
              echo "usage:"
              echo "    $0 TotalAccesses               -- Check total accesses."
              echo "    $0 TotalKBytes                 -- Check total KBytes."
              echo "    $0 Uptime                      -- Check uptime."
              echo "    $0 ReqPerSec                   -- Check requests per second."
              echo "    $0 BytesPerSec                 -- Check Bytes per second."
              echo "    $0 BytesPerReq                 -- Check Bytes per request."
              echo "    $0 BusyWorkers                 -- Check busy workers."
              echo "    $0 IdleWorkers                 -- Check idle workers."
              echo "    $0 version                     -- Version of this script."
              exit $rval;;
      esac
      
      if [ "$rval" -ne 0 ]; then
              echo "ZBX_NOTSUPPORTED"
      fi
      
      exit $rval
      
      #
      # end zapache
      Add to zabbix_agentd.conf:

      Code:
      UserParameter=apache[*],/home/zabbix/bin/zapache \$1
      And you can add your items:

      Code:
      Description            Type          Key                    Type of information  Update interval  Store value  History  Trends  Applications
        Apache/TotalAccesses.  ZABBIX agent  apache[TotalAccesses]  Numeric (integer)    60               As Is        7        365     APACHE
        Apache/TotalKBytes.    ZABBIX agent  apache[TotalKBytes]    Numeric (float)      60               As Is        7        365     APACHE
        Apache/Uptime.         ZABBIX agent  apache[Uptime]         Numeric (integer)    60               As Is        7        365     APACHE
        Apache/ReqPerSec.      ZABBIX agent  apache[RecPerSec]      Numeric (float)      60               As Is        7        365     APACHE
        Apache/BytesPerSec.    ZABBIX agent  apache[BytesPerSec]    Numeric (float)      60               As Is        7        365     APACHE
        Apache/BytesPerReq.    ZABBIX agent  apache[BytesPerReq]    Numeric (float)      60               As Is        7        365     APACHE
        Apache/BusyWorkers.    ZABBIX agent  apache[BusyWorkers]    Numeric (integer)    60               As Is        7        365     APACHE
        Apache/IdleWorkers.    ZABBIX agent  apache[IdleWorkers]    Numeric (integer)    60               As Is        7        365     APACHE
      Last edited by bashman; 02-11-2010, 10:21.
      978 Hosts / 16.901 Items / 8.703 Triggers / 44 usr / 90,59 nvps / v1.8.15

      Comment

      • Hichhiker
        Member
        • Nov 2004
        • 45

        #4
        Erm, I would stay away from zapache, at least in the form it is now.

        (bashman, you are not living up to your name, my friend ;-) )

        First of all, what is the deal with the REFRESH variable? I am guessing you believe you are assigning a command to a variable and the using this variable to execute it in every case, but you are really executing it once, assigning its output to a variable and then trying to execute that output as bash code. Both approaches are flawed but the way it is written is also dangerous. While wget should not be outputting anything (which is why the script probably works most of the time) - if it outputs anything, you either get something un-parsable making your script crash or something parsable making you script execute unintended code. And even if it does what I am guessing you intended - I do not see the point of executing same code in all those places when you can just execute it once before the "case" Remember the cardinal rule of programming - DRY - don't repeat yourself

        Besides this, the script uses a hardcoded directory "/home/zabbix/" which does not always exist. There is no point in using a local cached file if you are not actually using it as a cache. Which brings me to the other point - you do not cache anything. The data is retrieved every time for each variable - so really this is a very complicated way to do exact same thing as those one-liners do (which violates the KISS principle) and shares the same problem of creating 8 times the overhead and load on apache for requests to collect the data.

        Now, you can cache things (just remember to make the cache change atomic, so that if you have parallel execution, it does not break) but the perl script does something a bit different. Instead of reading each variable on demand, it uses one variable to trigger the script and does a single hit on the mod_status and parses all the data points and then send all of those point to zabbix using zabbix_sender. You could do all of that in bash as well, but it would be much more awk-ward (pardon the pun) and ugly. Not a big fan of perl, but this is one place it shines.

        Hope this helps,

        -HH

        Comment

        • bashman
          Senior Member
          • Dec 2009
          • 432

          #5
          Hi Hichhiker,

          First of all, thanks your for rapid response. Off course it is a flawed and dangerous script and there is no doubt it can be improved, it is only a sketch of what I'll like to have in bash, because I don't want to use neither zabbix_sender nor a perl script. I haven't seen any bash script through the forums, so that's why I decided to start something in order to get some help. (It worked)

          I would have a closer look to zapache keeping in mind the principles DIE - duplication is evil and KISS - keep it short and simple, and I'll post something better, or may be you'll like to post a version 1.1 of zapache, thanks again Hichhiker for your help.

          :-P - Bashman
          978 Hosts / 16.901 Items / 8.703 Triggers / 44 usr / 90,59 nvps / v1.8.15

          Comment

          • bashman
            Senior Member
            • Dec 2009
            • 432

            #6
            I think this is just a little bit better:

            Code:
            #! /bin/bash
            #
            # Name: zapache
            #
            # Checks Apache activity.
            #
            # Author: bashman
            #
            # Version: 1.1
            #
            
            zapachever="1.1"
            rval=0
            VAR=$(wget --quiet -O - http://localhost/server-status?auto)
            
            case $1 in
            'TotalAccesses')
                    echo "$VAR"|grep "Total Accesses:"|awk '{print $3}'
                    rval=$?;;
            'TotalKBytes')
                    echo "$VAR"|grep "Total kBytes:"|awk '{print $3}'
                    rval=$?;;
            'Uptime')
                    echo "$VAR"|grep "Uptime:"|awk '{print $2}'
                    rval=$?;;
            'ReqPerSec')
                    echo "$VAR"|grep "ReqPerSec:"|awk '{print $2}'
                    rval=$?;;
            'BytesPerSec')
                    echo "$VAR"|grep "BytesPerSec:"|awk '{print $2}'
                    rval=$?;;
            'BytesPerReq')
                    echo "$VAR"|grep "BytesPerReq:"|awk '{print $2}'
                    rval=$?;;
            'BusyWorkers')
                    echo "$VAR"|grep "BusyWorkers:"|awk '{print $2}'
                    rval=$?;;
            'IdleWorkers')
                    echo "$VAR"|grep "IdleWorkers:"|awk '{print $2}'
                    rval=$?;;
            'version')
                    echo "$zapachever"
                    exit $rval;;
            *)
                    echo "zapache version: $zapachever"
                    echo "usage:"
                    echo "    $0 TotalAccesses               -- Check total accesses."
                    echo "    $0 TotalKBytes                 -- Check total KBytes."
                    echo "    $0 Uptime                      -- Check uptime."
                    echo "    $0 ReqPerSec                   -- Check requests per second."
                    echo "    $0 BytesPerSec                 -- Check Bytes per second."
                    echo "    $0 BytesPerReq                 -- Check Bytes per request."
                    echo "    $0 BusyWorkers                 -- Check busy workers."
                    echo "    $0 IdleWorkers                 -- Check idle workers."
                    echo "    $0 version                     -- Version of this script."
                    exit $rval;;
            esac
            
            if [ "$rval" -ne 0 ]; then
                    echo "ZBX_NOTSUPPORTED"
            fi
            
            exit $rval
            
            #
            # end zapache
            Last edited by bashman; 08-04-2010, 07:19. Reason: There was a mistake on the script
            978 Hosts / 16.901 Items / 8.703 Triggers / 44 usr / 90,59 nvps / v1.8.15

            Comment

            • lgc78
              Member
              • Aug 2010
              • 35

              #7
              crashdummyMCH,

              I'm trying to configure my zabbix agent to to send results back to the server like you described in your post (UserParameter=apache.all,/usr/local/zabbix_agentd/apache.pl http://localhost). I can't seem to get it to work. Is this method still supported in the latest release of zabbix - 1.8.4? What i don't understand is how the apache.all item in my apache template will get populated - or does your apache.pl script take care of this? Any help would be appreciated.

              Thanks

              Comment

              • lgc78
                Member
                • Aug 2010
                • 35

                #8
                disregard... got it working. My issue was related to permissions.

                Comment


                • emil@hirestorm.com
                  [email protected] commented
                  Editing a comment
                  @lgc78,
                  I have configured the items, but how do I view the metrics from zabbix.
                  Last edited by [email protected]; 07-11-2019, 14:56.

                • emil@hirestorm.com
                  [email protected] commented
                  Editing a comment
                  Hello, I could not list values from zabbix,
                  Often while configuring the key , it shows in green, however the metrics do not pull up.

                  Please have a check on the error https://prnt.sc/pu1rso
                  Last edited by [email protected]; 08-11-2019, 07:28. Reason: added screenshot of error
              • sue
                Member
                • Mar 2011
                • 41

                #9
                Originally posted by crashdummyMCH
                --zabbix node--
                1. edit /etc/zabbix/zabbix_agentd.conf
                add the control script as a UserParameter
                #apache server status
                UserParameter=apache.all,/usr/local/zabbix_agentd/apache.pl http://localhost

                2. copy the attached apache.txt to /usr/local/zabbix_agentd/apache.pl
                3. copy the attached zabbix_sender.txt to /usr/local/zabbix_agentd/zabbix_sender.sh

                4. Configure httpd.conf to allow server-status page from localhost

                What this will allow is for the appache.pl to pull all data points and then send them off to the server while only loading the server-status page once
                --zabbix node--

                --zabbix web--
                1. create item apache controller
                type=zabbix agent (active)
                key=apache.all
                type of information=numeric
                2. create items for each data point pulled from apache.pl
                type=zabbix trapper
                key=apache.busyservers
                type of information=numeric
                -note repeat this step for all of the points collected by apache.pl MATCH THE KEY NAME EXACTLY
                --zabbix web--

                After all of this you should now start to see data come in for all of your data points. The advantage to this is that the host only hits the server-status page once guaranteeing that all of the data points are for the same time period.

                Hope this helps.
                I try and got this error. Hope u can help me

                30678:20110413:232150.776 Active check [apache[localhost,BusyWorkers]] is not supported. Disabled.
                30678:20110413:232350.014 Active check [apache[localhost,BytesPerReq]] is not supported. Disabled.
                30678:20110413:232350.019 Active check [apache[localhost,BytesPerSec]] is not supported. Disabled.

                Comment

                • bashman
                  Senior Member
                  • Dec 2009
                  • 432

                  #10
                  Originally posted by bashman
                  I think this is just a little bit better:

                  Code:
                  #! /bin/bash
                  #
                  # Name: zapache
                  #
                  # Checks Apache activity.
                  #
                  # Author: bashman
                  #
                  # Version: 1.1
                  #
                  
                  zapachever="1.1"
                  rval=0
                  VAR=$(wget --quiet -O - http://localhost/server-status?auto)
                  
                  case $1 in
                  'TotalAccesses')
                          echo "$VAR"|grep "Total Accesses:"|awk '{print $3}'
                          rval=$?;;
                  'TotalKBytes')
                          echo "$VAR"|grep "Total kBytes:"|awk '{print $3}'
                          rval=$?;;
                  'Uptime')
                          echo "$VAR"|grep "Uptime:"|awk '{print $2}'
                          rval=$?;;
                  'ReqPerSec')
                          echo "$VAR"|grep "ReqPerSec:"|awk '{print $2}'
                          rval=$?;;
                  'BytesPerSec')
                          echo "$VAR"|grep "BytesPerSec:"|awk '{print $2}'
                          rval=$?;;
                  'BytesPerReq')
                          echo "$VAR"|grep "BytesPerReq:"|awk '{print $2}'
                          rval=$?;;
                  'BusyWorkers')
                          echo "$VAR"|grep "BusyWorkers:"|awk '{print $2}'
                          rval=$?;;
                  'IdleWorkers')
                          echo "$VAR"|grep "IdleWorkers:"|awk '{print $2}'
                          rval=$?;;
                  'version')
                          echo "$zapachever"
                          exit $rval;;
                  *)
                          echo "zapache version: $zapachever"
                          echo "usage:"
                          echo "    $0 TotalAccesses               -- Check total accesses."
                          echo "    $0 TotalKBytes                 -- Check total KBytes."
                          echo "    $0 Uptime                      -- Check uptime."
                          echo "    $0 ReqPerSec                   -- Check requests per second."
                          echo "    $0 BytesPerSec                 -- Check Bytes per second."
                          echo "    $0 BytesPerReq                 -- Check Bytes per request."
                          echo "    $0 BusyWorkers                 -- Check busy workers."
                          echo "    $0 IdleWorkers                 -- Check idle workers."
                          echo "    $0 version                     -- Version of this script."
                          exit $rval;;
                  esac
                  
                  if [ "$rval" -ne 0 ]; then
                          echo "ZBX_NOTSUPPORTED"
                  fi
                  
                  exit $rval
                  
                  #
                  # end zapache
                  Added to the wiki:

                  http://www.zabbix.com/wiki/templates/apache#method_3
                  978 Hosts / 16.901 Items / 8.703 Triggers / 44 usr / 90,59 nvps / v1.8.15

                  Comment

                  • sue
                    Member
                    • Mar 2011
                    • 41

                    #11
                    apache not support by zabbix

                    i try use zapache but the status cannot support. i already copy bash script and put it it the right path. i put the user parameter in zabbix_agentd.conf. then i create template zapache. when i restart zabbix_agentd and want to see the result, it say cannot support. How come to solve my problem?

                    Comment

                    • bashman
                      Senior Member
                      • Dec 2009
                      • 432

                      #12
                      Originally posted by sue
                      i try use zapache but the status cannot support. i already copy bash script and put it it the right path. i put the user parameter in zabbix_agentd.conf. then i create template zapache. when i restart zabbix_agentd and want to see the result, it say cannot support. How come to solve my problem?
                      Have you configurated your apache for server-status?

                      Code:
                      <Location /server-status>
                          SetHandler server-status
                          Order deny,allow
                          Deny from all
                          Allow from localhost # or whatever site
                      </Location>
                      
                      ExtendedStatus On
                      Try to conect to your apache:

                      Code:
                      wget --quiet -O - http://<your apache ip>/server-status?auto
                      978 Hosts / 16.901 Items / 8.703 Triggers / 44 usr / 90,59 nvps / v1.8.15

                      Comment

                      • sue
                        Member
                        • Mar 2011
                        • 41

                        #13
                        Originally posted by bashman
                        Have you configurated your apache for server-status?
                        thanks..before this i dont know how to configure server status. Now it success. But i cannot monitor apache[RecPerSec]. Why? How to solve it?

                        Comment

                        • bashman
                          Senior Member
                          • Dec 2009
                          • 432

                          #14
                          Originally posted by sue
                          thanks..before this i dont know how to configure server status. Now it success. But i cannot monitor apache[RecPerSec]. Why? How to solve it?
                          What do you see if you wget your apache?

                          Code:
                          wget --quiet -O - http://<your apache ip>/server-status?auto
                          Can you dump your result?
                          978 Hosts / 16.901 Items / 8.703 Triggers / 44 usr / 90,59 nvps / v1.8.15

                          Comment

                          • sue
                            Member
                            • Mar 2011
                            • 41

                            #15
                            Originally posted by bashman
                            What do you see if you wget your apache?

                            Code:
                            wget --quiet -O - http://<your apache ip>/server-status?auto
                            Can you dump your result?
                            actually i cannot get the result if i use wget..i juz browse and get this result
                            Server uptime: 5 hours 16 minutes 35 seconds
                            Total accesses: 13372 - Total Traffic: 14.7 MB
                            CPU Usage: u341.74 s8.91 cu0 cs0 - 1.85% CPU load
                            .704 requests/sec - 809 B/second - 1149 B/request
                            1 requests currently being processed, 10 idle workers

                            _W_________....................................... ..............
                            .................................................. ..............
                            .................................................. ..............
                            .................................................. ..............
                            is it same if i use wget? because i get error when call wget
                            wget: invalid option -- 0
                            Usage: wget [OPTION]... [URL]...

                            Comment

                            Working...