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

Jorge jnerin at gmail.com
Fri Jan 23 19:05:33 CET 2015


Hi Jennings,

You could avoid the race by also checking the elapsed seconds
since varnish_uptime file was last written > new_varnish_uptime:

if [ $(($(date "+%s")-$(stat --printf="%Z" varnish_uptime))) -gt
$new_varnish_uptime ]; then

Note: completely untested code. And you can do integer arithmetic in bash
without spawning bc with $(( ))

El Fri Jan 23 2015 at 18:39:48, Jennings III, Raymond (<
raymond.jennings at nytimes.com>) escribió:

> 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}'
> >/var/nyt/logs/varnish/varnish_uptime
>
>
>
>
> The cron job is:
>
>
> #!/bin/bash
>
> 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 nytimes.com"
> fi
>
> 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
> *nytimes.com <http://nytimes.com/>*
> *Office: 212.556.7786 <212-556-7786>*
>
> *iPhone: 914.330.5074 <914-330-5074>E-mail: Raymond.Jennings at nytimes.com
> <Raymond.Jennings at nytimes.com>FaceTime: Raymond.Jennings at nytimes.com
> <Raymond.Jennings at nytimes.com>*
>  _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20150123/a48a433a/attachment.html>


More information about the varnish-misc mailing list