Ad Widget

Collapse

Monitoring Web Application Availability & Performance

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • helixblue
    Junior Member
    • Feb 2005
    • 6

    #1

    Monitoring Web Application Availability & Performance

    I needed to write a quick script to monitor the availability & performance of a web application cluster. The following quick script is set so that it follows redirects (HTTP Location header), which was required to measure it properly. It optionally searches for text in the output to measure whether or not the results were as expected, and returns -1 if the text is not output.

    The following was written and tested under Solaris 10. You may need to change the time and or awk command flags on other UNIX distributions so that it displays the same. If ksh is not available, switch it to bash.

    Code:
    #!/bin/ksh
    # syntax: checkurl URL TEXT
    
    URL=$1
    TEXT=$2
    
    TEMP_FILE=/tmp/checkurl.$$
    WEB_CMD="curl -L -o $TEMP_FILE"
    TIME="/usr/bin/time -p"
    
    elapsed=`$TIME $WEB_CMD $URL 2>&1 | grep real | awk '{ print $2 }'`
    
    # if we are supposed to check for some text 
    # instead of just saying "ya, it works".
    if [ "$TEXT" != "" ]; then
            if [ "`grep "$TEXT" $TEMP_FILE`" = "" ]; then
                    elapsed=-1
            fi
    fi
    
    rm $TEMP_FILE
    echo $elapsed
    Here is an example of it being used as a UserParameter:

    UserParameter=checkurl[reciprocal],/opt/local/bin/checkurl 'http://www.reciprocalnet.org/recipnet/search.jsp?browse=1' "Next page"
  • dpsantos
    Member
    Zabbix Certified Specialist
    • Mar 2005
    • 60

    #2
    Thank You!

    Now i can checkout the apache virtual hosts.... right?

    Comment

    • klavs
      Junior Member
      • Apr 2005
      • 18

      #3
      Can Zabbix test from the server-side(instead of checking in the local agent)?
      If so, I would alter the script to instead of returning 0 or 1 - returning 0 (for no connectivity) and a number, for the responsetime in seconds - like icmppingsec does.

      Comment

      • eWebtricity
        Junior Member
        • Mar 2005
        • 27

        #4
        Worked great for me on a RedHat9 agent, i just had to change the shell to /bin/bash in the checkurl script.

        Comment

        • Wolfgang
          Senior Member
          Zabbix Certified Trainer
          Zabbix Certified Specialist
          • Apr 2005
          • 116

          #5
          @helixblue

          Thank you for sharing the script.
          http://www.intellitrend.de
          Specialised in monitoring large environments and Zabbix API programming.

          Comment

          • llama
            Junior Member
            • Mar 2005
            • 13

            #6
            Thanks!

            Thank you very much for your web server status checking script!

            It works great!

            Comment

            • jpawlowski
              Member
              • May 2005
              • 45

              #7
              Hello helixblue!

              I just changed your script in order to check only the resultcode from the header. Here you are:

              Code:
              #!/bin/sh
              # syntax: checkurl URL
              
              URL=$1
              
              RESULT=`/usr/bin/curl -i $URL 2>/dev/null | grep ^HTTP/ | awk '{ print $2 }'`
              
              if [ "$RESULT" == "" ]; then
                  RESULT=0
              fi
              
              echo $RESULT
              Last edited by jpawlowski; 14-05-2005, 21:16.

              Comment

              • sojeshj
                Junior Member
                • Apr 2005
                • 9

                #8
                Server crawling isn't notified by this code.

                Originally posted by helixblue
                I needed to write a quick script to monitor the availability & performance of a web application cluster. The following quick script is set so that it follows redirects (HTTP Location header), which was required to measure it properly. It optionally searches for text in the output to measure whether or not the results were as expected, and returns -1 if the text is not output.

                The following was written and tested under Solaris 10. You may need to change the time and or awk command flags on other UNIX distributions so that it displays the same. If ksh is not available, switch it to bash.

                Code:
                #!/bin/ksh
                # syntax: checkurl URL TEXT
                
                URL=$1
                TEXT=$2
                
                TEMP_FILE=/tmp/checkurl.$$
                WEB_CMD="curl -L -o $TEMP_FILE"
                TIME="/usr/bin/time -p"
                
                elapsed=`$TIME $WEB_CMD $URL 2>&1 | grep real | awk '{ print $2 }'`
                
                # if we are supposed to check for some text 
                # instead of just saying "ya, it works".
                if [ "$TEXT" != "" ]; then
                        if [ "`grep "$TEXT" $TEMP_FILE`" = "" ]; then
                                elapsed=-1
                        fi
                fi
                
                rm $TEMP_FILE
                echo $elapsed
                Here is an example of it being used as a UserParameter:

                UserParameter=checkurl[reciprocal],/opt/local/bin/checkurl 'http://www.reciprocalnet.org/recipnet/search.jsp?browse=1' "Next page"

                This script worked fine for me. I have changed the elapsed=-1 to elapsed=0 and it works fine. It notifies me whenever the URL cannot be fetched, but if the apache on the server is running too slow, ie. if the server is crawling and tries to pull out the site for about 5 or 7 minutes, then whole server is as bad as being down and this code wont notify me unless the server/apache service goes completely down. Do you have any idea how to modify the code so that it checks to fetch the URL for about 10 seconds and if it cant be retrieved, then notify me. Can it be done.. Or does Zabbix have something inbuilt in it so that it compares with the time and notifies??

                Thanks in Advance..
                Soj

                Comment

                Working...