Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: bc91d57eb9
Fetching contributors…

Cannot retrieve contributors at this time

executable file 304 lines (254 sloc) 6.387 kB
#!/bin/sh
# varnish_gather - Gather debug information for varnish issues
# Copyright (C) 2010-2011 Varnish Software AS
# Author: Kristian Lyngstol <kristian@varnish-cache.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#
# Mostly harmless.
export LC_ALL=C
# Defines
HOSTPORT=""
NAME=""
VARNISHADMARG=""
SECRET=""
ITEM=0
TOPDIR="$(mktemp -d /tmp/varnishgather.XXXXXXXX)"
DIR="${TOPDIR}/varnishgather"
LOG="${DIR}/varnishgather.log"
ORIGPWD=$PWD
# Set up environment
mkdir -p ${DIR}
cd ${DIR}
# Helpers
log()
{
echo >>${LOG} "$*"
}
info()
{
echo 1>&2 "$*"
log "$*"
}
banner()
{
log "--------------------------------"
log "Item $ITEM: $*"
log
ITEM=$(( $ITEM + 1 ))
echo "Task: ${ITEM}: $*"
}
run()
{
banner "$*"
($*) >> ${LOG} 2>&1
log ""
}
runpipe_recurse() {
CMD="$1";
shift;
if [ "x$*" = "x" ]; then
${CMD} 2>&1
else
${CMD} 2>&1 | runpipe_recurse "$@"
fi
}
pipeprint()
{
CMD="$1";
shift;
if [ "x$*" = "x" ]; then
echo ${CMD}
else
echo ${CMD} "|" $(pipeprint "$@")
fi
}
runpipe()
{
banner $(pipeprint "$@")
runpipe_recurse "$@" >> ${LOG} 2>&1
log ""
}
mycat()
{
if [ -r $1 ]; then
run cat $1
fi
}
vadmin()
{
if [ ! -z "${VARNISHADMARG}" ]; then
run varnishadm ${VARNISHADMARG} $* 2>/dev/null
fi
}
getarg() {
ret=""
if ! which awk >/dev/null; then
info "awwww. No awk found. Automatic argument detection disabled."
return
fi
for a in `pgrep varnishd`; do
if [ ! -d /proc/${a} ]; then
info "proc nonfunctional. Automatic argument detection disabled."
return
fi
tmpret=$(awk -v RS='[[:cntrl:]]' -v arg=$1 's == 1 { sec=$0 }; $0 == arg {s=1}$0 != arg {s=0} END { print sec };' /proc/${a}/cmdline)
if [ x$ret != "x" ] && [ $ret != $tmpret ]; then
log "Weird argument mismatch: $ret vs $tmpret found"
info "(Using last found/listed)"
fi
ret=${tmpret}
done
echo ${ret}
}
usage() {
cat <<_EOF_
Usage: $0 [-n name] [-T host:port] [-S secretfile] [-h]
Varnishgather gathers various system information into a single
tar-ball.
-n <name> Provide the name, same as the -n argument to varnishd
-T <host:port> Provide host and port for the management interface
Same as the -T option to varnishd.
-S <secretfile> Provide a secret file, same as -S to varnishd.
-h Show this text.
All arguments are optional. varnishgather will attempt to detect the
arguments automatically, but will likely be confused if you have multiple
varnish servers running. In other words: Use -T, -n and -S if you have
multiple varnishd servers running on the same server.
_EOF_
exit 1
}
##############################
# Proper execution starts here
##############################
info "Working directory: ${DIR}"
TEMP=`getopt n:T:S:h "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$TEMP"
while true ; do
case "$1" in
-n) NAME=$2 ; shift 2;;
-T) HOSTPORT=$2; shift 2;;
-S)
if [ -r $2 ]; then
SECRET="-S $2";
else
info "Secret file $2 not readable."
exit 1;
fi
shift 2;;
-h) usage; exit 0 ;;
--) shift; break;;
*) echo "internal error"; exit 1;;
esac
done
if [ -z "$HOSTPORT" ]; then
HOSTPORT=$(getarg -T)
if [ -z "$HOSTPORT" ]; then
info "Without a hostname:port for the admin interface, this script is less useful"
else
banner "Found hostport(-T argument): ${HOSTPORT}"
fi
fi
if [ -z "$SECRET" ]; then
sec=$(getarg -S)
if [ ! -z ${sec} ]; then
if [ -r ${sec} ]; then
banner "Found secretfile(-S argument) ${sec} and it's readable. Using it."
SECRET="-S ${sec}"
elif [ -f /etc/varnish/secret ]; then
banner "Found secretfile(-S argument) ${sec} but it's not readable"
fi
else
banner "Didn't find any -S argument"
fi
fi
STATCMD=""
if [ ! -z "$NAME" ]; then
STATCMD="-n $NAME"
fi
VARNISHADMARG="${SECRET} -T ${HOSTPORT}"
banner "Complete varnishadm command line deduced to: ${VARNISHADMARG}"
run date
run dmesg
mycat /var/log/dmesg
for a in /var/log/messages /var/log/syslog; do
if [ -r $a ]; then
run grep varnish $a
fi
done
mycat /proc/cpuinfo
mycat /proc/version
runpipe "ps aux" "egrep '(varnish|apache|mysql|nginx|httpd)'"
runpipe "netstat -np" "wc -l"
runpipe "netstat -np" "grep ESTABLISHED" "wc -l"
run free -m
run vmstat 5 5
run lsb_release -a
run sysctl -a
run varnishstat -V
run netstat -s
run ip a
run ip n
run ip r
run ip -s l
run uname -a
run mount
run df -h
banner "ps aux | egrep '(varnish|apache|mysql|nginx|httpd)'"
ps aux | egrep '(varnish|apache|mysql|nginx|httpd)' >> ${LOG}
run varnishstat -1 $STATCMD
NETSTAT="/bin/netstat"
if [ -x "$NETSTAT" ]; then
run ${NETSTAT} -nlpt
run ${NETSTAT} -np
fi
run iptables -n -L
for a in /etc/varnish/*vcl; do
mycat $a
done
mycat /etc/default/varnish
mycat /etc/sysconfig/varnish
run find /usr/local -name varnish
if [ -z "${VARNISHADMARG}" ]; then
banner "NO ADMINPORT SUPPLIED OR FOUND"
fi
# vadmin() tests for VARNISHADMARG as necessary
vadmin vcl.list
vadmin vcl.show boot
vadmin param.show
vadmin purge.list
vadmin ban.list
vadmin debug.health
vadmin panic.show
run varnishlog -d -k 5000 -w ${DIR}/varnishlog.raw $STATCMD
banner "End"
cd ${TOPDIR}
DATE="$(date +%Y-%m-%d-%H%M%S)"
tar czf ${TOPDIR}/varnishgather.tar.gz varnishgather/
echo Log: ${LOG}
cd $ORIGPWD
copyto="varnishgather.${DATE}.log"
if [ ! -f $copyto ]; then
cp ${LOG} $copyto || exit 1
echo "Log is in ${copyto}."
fi
copytogz="varnishgather.${DATE}.tar.gz"
if [ ! -f $copytogz ]; then
cp ${TOPDIR}/varnishgather.tar.gz $copytogz || exit 1
echo "Data to submit: $copyto (includes log)"
echo " You can delete the workdir: rm -r ${TOPDIR}"
fi
Jump to Line
Something went wrong with that request. Please try again.