Ad Widget

Collapse

Apache & zabbix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • steveboyson
    Senior Member
    • Jul 2013
    • 582

    #1

    Apache & zabbix

    Hi folks,
    I made a different version of https://www.zabbix.com/wiki/templates/apache
    My version works with zabbix_sender and trapper items.
    It caches the output and fetches only if the cached file is too old (can be set via parameter INTERVAL).


    PROS: less work & load on zabbix agent side
    CONS: values may be less accurate due to caching

    Download script and template here:
  • sccuser
    Member
    • May 2013
    • 77

    #2
    Dear stevenboyson,

    Thanks for the great script and template.
    I did exactly as your instruction but no luck to display the graphs.

    Help me pls.




    Comment

    • steveboyson
      Senior Member
      • Jul 2013
      • 582

      #3
      What happens if you execute the script from within your zabbix server as
      "bash -x apache_zabbix.sh"?

      Have you checked the variables in the script? Are the settings
      Code:
      zbx_send="/usr/bin/zabbix_sender -c /etc/zabbix/zabbix_agentd.conf"
      zbx_server="zabbix"
      correct?
      Is wget in the correct location or correct configured in the script?
      Is apache's mod_status enabled? Can you access it via
      Code:
      http://<your-server-name>/server-status?auto
      ?

      Pls. check all that.

      Comment

      • sccuser
        Member
        • May 2013
        • 77

        #4
        Originally posted by steveboyson
        What happens if you execute the script from within your zabbix server as
        "bash -x apache_zabbix.sh"?

        Have you checked the variables in the script? Are the settings
        Code:
        zbx_send="/usr/bin/zabbix_sender -c /etc/zabbix/zabbix_agentd.conf"
        zbx_server="zabbix"
        correct?
        Is wget in the correct location or correct configured in the script?
        Is apache's mod_status enabled? Can you access it via
        Code:
        http://<your-server-name>/server-status?auto
        ?

        Pls. check all that.
        Dear steveboyson,

        Forgot to let you know that I'm trying to monitor apache from remote machine, not Zabbix server itself.

        When trying to run bash -x /home/zabbix/bin/zabbix_apache.sh (I locate the script in here), it returns

        [root@xentos ~]# bash -x /home/zabbix/bin/zabbix_apache.sh
        + zapachever=1.0_MH
        + rval=0
        + RES=
        + INTERVAL=3
        + zbx_send='/usr/local/zabbix_agentd/bin/zabbix_sender -c /usr/local/etc/zabbix_agentd.conf'
        + zbx_server=zabbix
        ++ hostname -s
        + zbx_host=xentos
        + prefix=apache
        + [[ 0 == 0 ]]
        + APACHE=localhost
        + apache_status_file=/tmp/zbx_apache_localhost.txt
        ++ find /tmp/zbx_apache_localhost.txt -cmin +3
        + '[' x/tmp/zbx_apache_localhost.txt '!=' x ']'
        + fetch
        + wget --quiet -O /tmp/zbx_apache_localhost.txt 'http://localhost/server-status?auto'
        + rval=0
        ++ do_zbx_send Stats_source FETCH
        +++ /usr/local/zabbix_agentd/bin/zabbix_sender -c /usr/local/etc/zabbix_agentd.conf -z zabbix -s xentos -k 'apache[Stats_source]' -o FETCH
        ++ RES='Sending failed. Use option -vv for more detailed output.'
        ++ echo Sending failed. Use option -vv for more detailed output.
        + RES='Sending failed. Use option -vv for more detailed output.'
        + keys='TotalAccesses TotalKBytes Uptime ReqPerSec BytesPerSec BytesPerReq BusyWorkers IdleWorkers version WaitingForConnection StartingUp ReadingRequest SendingReply'
        + keys='TotalAccesses TotalKBytes Uptime ReqPerSec BytesPerSec BytesPerReq BusyWorkers IdleWorkers version WaitingForConnection StartingUp ReadingRequest SendingReply KeepAlive DNSLookup ClosingConnection Logging GracefullyFinishing IdleCleanupOfWorker OpenSlotWithNoCurrentProcess'
        ++ cat /tmp/zbx_apache_localhost.txt
        + VAR='Total Accesses: 1
        Total kBytes: 544
        CPULoad: .0588235
        Uptime: 68
        ReqPerSec: .0147059
        BytesPerSec: 8192
        BytesPerReq: 557056
        BusyWorkers: 1
        IdleWorkers: 10
        Scoreboard: ______W____....................................... .................................................. .................................................. .................................................. .................................................. ......'
        + OUT=

        and so on...

        I also modify the script to appropriate

        zapachever="1.0_MH"
        rval=0
        RES=''
        # minutes
        INTERVAL=3

        zbx_send="/usr/local/zabbix_agentd/bin/zabbix_sender -c /usr/local/etc/zabbix_agentd.conf"
        zbx_server="zabbix"
        zbx_host=`hostname -s`
        prefix=apache

        do_zbx_send ()

        Please tell me how to do the below

        Is wget in the correct location or correct configured in the script?
        Is apache's mod_status enabled? YES

        Last edited by sccuser; 03-03-2014, 15:35.

        Comment

        • steveboyson
          Senior Member
          • Jul 2013
          • 582

          #5
          Code:
          +++ /usr/local/zabbix_agentd/bin/zabbix_sender -c /usr/local/etc/zabbix_agentd.conf -z zabbix -s xentos -k 'apache[Stats_source]' -o FETCH
          and
          Code:
          ++ RES='Sending failed. Use option -vv for more detailed output.'
          ++ echo Sending failed. Use option -vv for more detailed output.
          + RES='Sending failed. Use option -vv for more detailed output.'
          need to be checked. Is "zabbix" the name of your zabbix server?

          wget seems to be installed correctly, by the way.

          Pls. give some more details about your configuration.

          Comment

          • sccuser
            Member
            • May 2013
            • 77

            #6
            Dear steveboyson,

            My apologize about the incorrect zabbix server name in the script, I changed to proper one and run "bash -x ..." again then receive the below, it seem likely working with a little bit error this time (firewall?), but the graph cannot be displayed as proper.

            [root@xentos ~]# bash -x /home/zabbix/bin/zabbix_apache.sh
            + zapachever=1.0_MH
            + rval=0
            + RES=
            + INTERVAL=3
            + zbx_send='/usr/local/zabbix_agentd/bin/zabbix_sender -c /usr/local/etc/zabbix_agentd.conf'
            + zbx_server=xibbaz
            ++ hostname -s
            + zbx_host=xentos
            + prefix=apache
            + [[ 0 == 0 ]]
            + APACHE=localhost
            + apache_status_file=/tmp/zbx_apache_localhost.txt
            ++ find /tmp/zbx_apache_localhost.txt -cmin +3
            + '[' x/tmp/zbx_apache_localhost.txt '!=' x ']'
            + fetch
            + /usr/bin/wget --quiet -O /tmp/zbx_apache_localhost.txt 'http://localhost/server-status?auto'
            + rval=0
            ++ do_zbx_send Stats_source FETCH
            +++ /usr/local/zabbix_agentd/bin/zabbix_sender -c /usr/local/etc/zabbix_agentd.conf -z xibbaz -s xentos -k 'apache[Stats_source]' -o FETCH
            ++ RES='info from server: "processed: 0; failed: 1; total: 1; seconds spent: 0.000031"
            sent: 1; skipped: 0; total: 1'
            ++ echo info from server: '"processed:' '0;' failed: '1;' total: '1;' seconds spent: '0.000031"' sent: '1;' skipped: '0;' total: 1
            + RES='info from server: "processed: 0; failed: 1; total: 1; seconds spent: 0.000031" sent: 1; skipped: 0; total: 1'
            + keys='TotalAccesses TotalKBytes Uptime ReqPerSec BytesPerSec BytesPerReq BusyWorkers IdleWorkers version WaitingForConnection StartingUp ReadingRequest SendingReply'
            + keys='TotalAccesses TotalKBytes Uptime ReqPerSec BytesPerSec BytesPerReq BusyWorkers IdleWorkers version WaitingForConnection StartingUp ReadingRequest SendingReply KeepAlive DNSLookup ClosingConnection Logging GracefullyFinishing IdleCleanupOfWorker OpenSlotWithNoCurrentProcess'
            ++ cat /tmp/zbx_apache_localhost.txt
            + VAR='Total Accesses: 10888
            Total kBytes: 207350
            CPULoad: .0585563
            Uptime: 57671
            ReqPerSec: .188795
            BytesPerSec: 3681.68
            BytesPerReq: 19501
            BusyWorkers: 1
            IdleWorkers: 16
            Scoreboard: ____W____________................................. .................................................. .................................................. .................................................. .................................................. ......'
            + OUT=
            + for key in '$keys'
            ++ getValue TotalAccesses
            ++ CASE_VALUE=TotalAccesses
            ++ case $CASE_VALUE in
            ++ grep 'Total Accesses:'
            ++ echo 'Total Accesses: 10888
            Total kBytes: 207350
            CPULoad: .0585563
            Uptime: 57671
            ReqPerSec: .188795
            BytesPerSec: 3681.68
            BytesPerReq: 19501
            BusyWorkers: 1
            IdleWorkers: 16
            Scoreboard: ____W____________................................. .................................................. .................................................. .................................................. .................................................. ......'
            ++ awk '{print $3}'
            ++ rval=0
            + val=10888
            ++ do_zbx_send TotalAccesses 10888
            +++ /usr/local/zabbix_agentd/bin/zabbix_sender -c /usr/local/etc/zabbix_agentd.conf -z xibbaz -s xentos -k 'apache[TotalAccesses]' -o 10888
            ++ RES='info from server: "processed: 0; failed: 1; total: 1; seconds spent: 0.000031"
            sent: 1; skipped: 0; total: 1'
            ++ echo info from server: '"processed:' '0;' failed: '1;' total: '1;' seconds spent: '0.000031"' sent: '1;' skipped: '0;' total: 1
            + RES='info from server: "processed: 0; failed: 1; total: 1; seconds spent: 0.000031" sent: 1; skipped: 0; total: 1'
            + for key in '$keys'
            ++ getValue TotalKBytes
            ++ CASE_VALUE=TotalKBytes
            ++ case $CASE_VALUE in
            ++ grep 'Total kBytes:'
            ++ echo 'Total Accesses: 10888
            Total kBytes: 207350
            CPULoad: .0585563
            Uptime: 57671
            ReqPerSec: .188795
            BytesPerSec: 3681.68
            BytesPerReq: 19501
            BusyWorkers: 1
            IdleWorkers: 16
            Scoreboard: ____W____________................................. .................................................. .................................................. .................................................. .................................................. ......'
            ++ awk '{print $3}'
            ++ rval=0
            + val=207350

            and so on...
            Here below is what I did:
            1. copy the zabbix_apache.sh to /home/zabbix/bin

            2. chmod +x /home/zabbix/bin/zabbix_apache.sh + granting permission for "zabbix" group.



            3. modify zabbix_apache.sh
            zbx_send="/usr/local/zabbix_agentd/bin/zabbix_sender -c /usr/local/etc/zabbix_agentd.conf"
            zbx_server="xibbaz"
            4. adding UserParameter into /usr/local/etc/zabbix_agentd.conf
            UserParameter=apache[*],/home/zabbix/bin/zabbix_apache.sh $1
            5. Import the template from XML file >>> create graph.
            but it's still not working so far.

            Adding my firewall configuration



            Please help me!
            Last edited by sccuser; 04-03-2014, 03:09. Reason: adding screenshot

            Comment

            • steveboyson
              Senior Member
              • Jul 2013
              • 582

              #7
              Ok, that requires some more questions. Are these assumptions correct?

              - xentos
              is the machine which apache webserver you want to monitor and where the script is supposed to run
              - xibbaz
              is the zabbix server

              Can you please check if all items from the imported template are correctly imported? Check under "Configuration - Hosts - xentos" and look for items named "apache["

              Is the script hooked into xentos' zabbix_agentd.conf file via "UserParameter=apache_stat[*]=/home/zabbix/bin/zabbix_apache.sh $1 $2 $3" entry?

              Can you telnet to xibbaz port 10051 from xentos?

              What does the zabbix_server.log say? Any errors?

              Comment

              • sccuser
                Member
                • May 2013
                • 77

                #8
                Dear steveboyson,

                Exactly!
                xentos = is the machine where apache running
                xibbaz = zabbix server

                I'm posting again the screenshot of items.



                Is the script hooked into xentos' zabbix_agentd.conf file via "UserParameter=apache_stat[*]=/home/zabbix/bin/zabbix_apache.sh $1 $2 $3" entry?
                Yes it's already configured, but just $1 only, not including $2 $3 as the above.

                Yes, it's possible to ping tcp 10051 from xentos to zibbax



                The zabbix_server.log

                2551:20140304:151520.705 cannot send list of active checks to [10.x.x.x]: host [xentos] not found
                2572:20140304:151538.638 cannot process step "Log in" of web scenario "Zabbix frontend" on host "Zabbix server": error in step variables "{sid}=regex:name="sid" value="([0-9a-z]{16})"": cannot extract the value of "{sid}" from response
                2551:20140304:151720.794 cannot send list of active checks to [10.x.x.x]: host [xentos] not found
                2572:20140304:151838.795 cannot process step "Log in" of web scenario "Zabbix frontend" on host "Zabbix server": error in step variables "{sid}=regex:name="sid" value="([0-9a-z]{16})"": cannot extract the value of "{sid}" from response
                2553:20140304:151920.871 cannot send list of active checks to [10.x.x.x]: host [xentos] not found
                10.x.x.x is the IP addresss of xentos

                Comment

                • steveboyson
                  Senior Member
                  • Jul 2013
                  • 582

                  #9
                  I think I found the error.

                  The host's name in Zabbix has nothing to do with the real hostname of the system.

                  I see that in zabbix your host is defined as "xentos...org" while in the script it tries to send data to a host called "xentos".

                  change the line in the script which reads "hostname -s" to just "hostname".

                  The "-s" strips the domain part from the hostname (which is fine for our environment but not yours).

                  Comment

                  • sccuser
                    Member
                    • May 2013
                    • 77

                    #10
                    Dear steveboyson,

                    It's still persistent







                    From your XML template, I can see the Interval time is not configured, any clues?
                    Last edited by sccuser; 04-03-2014, 11:11. Reason: input a question

                    Comment

                    • steveboyson
                      Senior Member
                      • Jul 2013
                      • 582

                      #11
                      What does
                      Code:
                      /usr/local/zabbix_agentd/bin/zabbix_sender -c /usr/local/etc/zabbix_agentd.conf -z xibbaz -s xentos.YOURDOMAIN.org -k 'apache[Stats_source]' -o FETCH
                      show?

                      The interval is only set for the item "Apache/workerScript" as it is the executed script. It has a defined interval of 300 seconds in the template.
                      All the other items are trapper items, that means the values gathered by the script get sent (pushed) to the zabbix server. They have no interval.

                      Comment

                      • sccuser
                        Member
                        • May 2013
                        • 77

                        #12
                        Dear steveboyson,

                        Thanks for the explanation, please check the output

                        Comment

                        • steveboyson
                          Senior Member
                          • Jul 2013
                          • 582

                          #13
                          That looks good, it accepted the value. You should see it under "Monitoring - Latest data".

                          Now the script should be running ok, I think.

                          Comment

                          • sccuser
                            Member
                            • May 2013
                            • 77

                            #14
                            Dear steveboyson,

                            It seems to be working just a half, at the time I run FETCH command.
                            The graph still not yet be displayed at all.






                            Should I change the "localhost" to xentos's IP address?

                            Last edited by sccuser; 04-03-2014, 16:03. Reason: update screenshot

                            Comment

                            • steveboyson
                              Senior Member
                              • Jul 2013
                              • 582

                              #15
                              No, localhost is usually fine. Please check the permissions of the file /tmp/zbx_apache_localhost.txt (or the like). If it belongs to root, it wiull not work.

                              When you start the script as root, this file gets created. When zabbix wants to execute the script, it also tries to create that file but cannot due to the file already existing. Either remove it or give it "chown zabbix /tmp/zbx_apache_localhost.txt" so that the user under which the zabbix-agentd is running is able to overwite it.

                              What are the other "zabbix_send" commands in the script's output? Don't they make their way into zabbix?

                              Comment

                              Working...