Skip to content

Instantly share code, notes, and snippets.

@gcorrao
Created June 22, 2011 21:19
Show Gist options
  • Save gcorrao/1041243 to your computer and use it in GitHub Desktop.
Save gcorrao/1041243 to your computer and use it in GitHub Desktop.
Script that takes varnish stats and writes out a log-like file
#/bin/bash -l
function get_stats {
(
echo "stats"
echo ""
sleep 1
echo "quit"
) | telnet $1 6082 2>&1
}
STATS=`get_stats $1`
V_HITS=`echo "$STATS" | grep "Cache hits" | grep -v "Cache hits for pass" | awk {'print $1'}`
V_PASS=`echo "$STATS" | grep "Cache hits for pass" | awk {'print $1'}`
V_MISS=`echo "$STATS" | grep "Cache miss" | awk {'print $1'}`
let V_TOTAL="$V_HITS+$V_MISS"
let V_RATIO="$V_HITS*100/$V_TOTAL"
echo "HITS= $V_HITS"
echo "MISS= $V_MISS"
echo "HIT_RATIO= $V_RATIO%"
echo "PASS= $V_PASS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment