Home > BashScripts, Nagios, plugins > varnish check_hitratio

varnish check_hitratio

March 25th, 2014 Leave a comment Go to comments

We need to know if varnish is caching hit ratio is as it should.
So I wrote this simple bash plugin for nagios.

./check_hitratio.sh 96 90
OK – 98.67% hit_ratio|hit_ratio=98.67

96 = warning 90 = critical
if no arg is passed it assumes the default 95 90

Here is the code:


#!/bin/bash
# bash simple script to get the varnish 3 hit_ratio
# by Felipe Ferreira Mar/2014

if [ $# -ne 2 ]; then
# set default hit_ratio thresholds
CRIT=90
WARN=95
else
CRIT=$1 
WARN=$2
fi

T=`varnishstat -1 -f client_req |awk '{print $3 }' |head -1`
M=`varnishstat -1 -f cache_miss |awk '{print $3 }' |tail -1`
#echo "Total  req: " $T 
#echo "Total miss: " $M
R1=`perl -e "printf('%.2f',100*${M})"`
R2=`perl -e "printf('%.2f',${R1}/${T})"`
R3=`perl -e "printf('%.2f',100-${R2})"`

MSG="${R3}% hit_ratio|hit_ratio=${R3}"
H=`perl -e "printf('%.0f',${R3})"`
#echo "DEBUG: $H $CRIT $WARN"

if [ "$H" -le "$CRIT" ]; then
	echo "CRITICAL - $MSG"
	exit 2
fi
if [ "$H" -le "$WARN" ]; then
	echo "WARNING - $MSG"
	exit 1
else
	echo "OK - $MSG"
	exit 0
fi
  1. No comments yet.
  1. No trackbacks yet.

VAMOVE *

*