Skip to content

Instantly share code, notes, and snippets.

@agramajo
Created March 28, 2017 18:19
Show Gist options
  • Save agramajo/1f6641b911ed1c02a90525269548bc4d to your computer and use it in GitHub Desktop.
Save agramajo/1f6641b911ed1c02a90525269548bc4d to your computer and use it in GitHub Desktop.
Show varnish stats
#!/usr/bin/perl
use POSIX qw( strftime );
$output = `varnishstat -1`;
%hash = $output =~ /([._\w]+)\s+(\d+)/g;
$date = strftime "%H:%M:%S", localtime;
$total_caches = $hash{'MAIN.cache_hit'} + $hash{'MAIN.cache_miss'};
$cache_hit_rate = sprintf "%0.2f", $hash{'MAIN.cache_hit'}/$total_caches*100;
$cache_miss_rate = sprintf "%0.2f", $hash{'MAIN.cache_miss'}/$total_caches*100;
$work_thread_rate = sprintf "%0.2f", $hash{'MAIN.threads'}/$hash{'MAIN.threads_created'}*100;
print <<EOF;
$date
client_connections $hash{'MAIN.sess_conn'}
client_requests $hash{'MAIN.client_req'}
cache_hits $hash{'MAIN.cache_hit'}
cache_misses $hash{'MAIN.cache_miss'}
cache_hit_rate $cache_hit_rate
cache_miss_rate $cache_miss_rate
total_caches $total_caches
sessions $hash{'MAIN.s_sess'}
work_thread $hash{'MAIN.threads'}
work_thread_rate $work_thread_rate
backend_fail $hash{'MAIN.backend_fail'}
lru_nuked $hash{'MAIN.n_lru_nuked'}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment