I think it is important to know how much time it is taking for the varnish
to go to the backend (webserver) and return.
The script will show the response time of more then on site, to make
it work be sure to have the varnish VCL probe setup.
To test run
#varnishadm debug.health

Here is the code:

#!/bin/bash
#Get current time of backend response on Varnish Servers
# Requires the use of backend probes config in VLC
#By Felipe Ferreira October 2010
# Exit codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
#Variables
site="bobo"
maxconwarn=1
maxconcrti=2
perfdata=1
#Check arguments print help
if [ $# -lt 1 ]; then
    echo "Uso: $0 -s  [-w|--warning ] [-c|--critical ]"
    exit $STATE_UNKNOWN
fi
#GET ARGS
while test -n "$1"; do
    case "$1" in
        --help)
            echo "Uso: $0 -s  [-w|--warning ] [-c|--critical ] "
            exit $STATE_OK
            ;;
        -h)
            echo "Uso: $0 -s  [-w|--warning ] [-c|--critical ] "
            exit $STATE_OK
            ;;
                --warning)
            maxconwarn=$2
            shift
            ;;
        -w)
            maxconwarn=$2
            shift
            ;;
        --critical)
            maxconcrit=$2
            shift
            ;;
        -c)
            maxconcrit=$2
            shift
            ;;
        -s)
            site=$2
            shift
            ;;
        -site)
            site=$2
            shift
            ;;
    esac
   shift
done
if [ $site = "bobo" ]; then
 result=`/usr/local/varnish/bin/varnishadm -T 127.0.0.1:1234 debug.health|grep probes |cut -b 37-45 |head -n 1`
elif  [ $site = "rapa" ];  then
 result=`/usr/local/varnish/bin/varnishadm -T 127.0.0.1:1234 debug.health|grep probes |cut -b 37-45 |head -n 2|tail -n 1`
else
 echo "Missing Site parameter"
 echo "Uso: $0 -s  [-w|--warning ] [-c|--critical ] "
 exit $STATE_UNKNOWN
fi
#echo $result
if [ $(echo "$result > $maxconwarn"|bc) -eq 1 ]; then
        OUTPUT="WARNING - Backend $site response = $result"
        exitstatus=$STATE_WARNING
fi
if [  $(echo "$result > $maxconcrit"|bc) -eq 1 ]; then
        OUTPUT="CRITICAL - Backend $site response = $result"
        exitstatus=$STATE_CRITICAL
fi
if [ $(echo "$result < $maxconwarn"|bc) -eq 1 ]; then
   OUTPUT="OK - Backend $site response = $result"
   exitstatus=$STATE_OK
fi
if [ $perfdata -eq 1 ]; then
    OUTPUT="$OUTPUT|BackendResponse=$result"
fi
echo $OUTPUT
exit $exitstatus
Tags: , , , , , ,

2 thoughts on “Varnish Backend Response Monitor

Leave a Reply

Your email address will not be published. Required fields are marked *