#!/usr/bin/perl use strict; sub unit { my $num = shift; my @unit = qw(B KB MB GB); while( @unit ) { last if( $num < 1024 ); $num/=1024; } continue { shift @unit; } return($num, $unit[0]); } # unit my %stat; open(FH, "varnishstat -1 -f client_req,cache_hit,cache_hitpass,cache_miss,sm_balloc,sm_bfree |") or die "cant varnishstat: $!" ; while( ) { my($param, $value, $comment) = split /\s+/; $stat{$param} = $value; } close(FH); #foreach my $param (keys %stat) { # printf "%s - %s\n", $param, $stat{$param}; #} my($client_req, $cache_hit, $cache_hitpass, $cache_miss) = ($stat{client_req}, $stat{cache_hit}, $stat{cache_hitpass}, $stat{cache_miss}); my $other = $client_req - $cache_hit - $cache_hitpass - $cache_miss; printf("hit=%.2f%%, miss=%.2f%%, other=%.2f%%\n", ($cache_hit+$cache_hitpass)*100/$client_req, ($cache_miss)*100/$client_req, ($other)*100/$client_req); my($sm_balloc, $sm_bfree) = ($stat{sm_balloc}, $stat{sm_bfree}); printf("use=%.1f%s(%.2f%%) / free=%.1f%s(%.2f%%)\n", &unit($sm_balloc), $sm_balloc*100/($sm_balloc+$sm_bfree), &unit($sm_bfree), $sm_bfree*100/($sm_balloc+$sm_bfree)); #print "client_req / $client_req\n"; #print "cache_hit / $cache_hit\n"; #print "cache_hitpass / $cache_hitpass\n"; #print "cache_miss / $cache_miss\n"; #print "sm_balloc / $sm_balloc\n"; #print "sm_bfree / $sm_bfree\n"; #echo -------------------------------------- #client_req 104279 8.55 Client requests received #cache_hit 84199 6.91 Cache hits #cache_hitpass 0 0.00 Cache hits for pass #cache_miss 12941 1.06 Cache misses #sm_balloc 191041536 . bytes allocated #sm_bfree 882700288 . bytes free