Small (hopefully helpful) script to monitor Varnish's uptime

Jennings III, Raymond raymond.jennings at
Fri Jan 23 18:36:17 CET 2015

I was having a lot of segmenation faults in Varnish (due to our own
mistakes) but unless you are monitoring syslog or /var/log/kern you might
not ever know it's happening given that the child process restarts very
quickly so I wrote this little cron job:

You first have to bootstrap this right after you first install and start
varnish with:

/usr/bin/varnishstat -1 | /bin/grep 'uptime' | /bin/awk '{ print $2}'

The cron job is:


new_varnish_uptime=`/usr/bin/varnishstat -1 | /bin/grep 'uptime' | /bin/awk
'{ print $2}'`
old_varnish_uptime=`cat /var/nyt/logs/varnish/varnish_uptime`

delta_time=$(echo "$new_varnish_uptime - $old_varnish_uptime" | /usr/bin/bc)

if [[ $delta_time -lt 0 ]]; then
   echo "Uh oh!!!  Varnish was restarted.  It's uptime is now
$new_varnish_uptime and it used to be $old_varnish_uptime." | /bin/mail -s
"Varnish Server Restarted!" "Raymond.Jennings at"

echo $new_varnish_uptime >/var/nyt/logs/varnish/varnish_uptime

There is a race condition if Varnish is restarting faster than the
frequency of the cron job running.

Raymond Jennings III
* <>*
*Office: 212.556.7786 <212-556-7786>*

*iPhone: 914.330.5074 <914-330-5074>E-mail: Raymond.Jennings at
<Raymond.Jennings at>FaceTime: Raymond.Jennings at
<Raymond.Jennings at>*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the varnish-misc mailing list