PDA

View Full Version : Monitoring Web Application Availability & Performance


helixblue
16-02-2005, 20:54
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.

#!/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
31-03-2005, 14:50
Now i can checkout the apache virtual hosts.... right?

klavs
06-04-2005, 17:08
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.

eWebtricity
01-05-2005, 18:20
Worked great for me on a RedHat9 agent, i just had to change the shell to /bin/bash in the checkurl script.

Wolfgang
04-05-2005, 00:08
@helixblue

Thank you for sharing the script. :)

llama
10-05-2005, 23:33
Thank you very much for your web server status checking script!

It works great!

:):)

jpawlowski
14-05-2005, 22:14
Hello helixblue!

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


#!/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

sojeshj
19-05-2005, 16:23
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.

#!/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