mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-22 12:30:07 +00:00
240f9fd1bc
Julien Antony and Matthieu Huguet of Prizee provided this convenient script to monitor activity via the unix socket. It requires presence of the "socat" utility. Example of usage : lb1:/home/scripts# ./stats_haproxy.sh -s prizee_media,FRONTEND 189 session/s (avg: 189 ) 1040 concurrent sessions 182 session/s (avg: 185 ) 1022 concurrent sessions 164 session/s (avg: 178 ) 1015 concurrent sessions 175 session/s (avg: 177 ) 1015 concurrent sessions 226 session/s (avg: 187 ) 1031 concurrent sessions 252 session/s (avg: 198 ) 1056 concurrent sessions 273 session/s (avg: 208 ) 1072 concurrent sessions 268 session/s (avg: 216 ) 1080 concurrent sessions 271 session/s (avg: 222 ) 1131 concurrent sessions 241 session/s (avg: 224 ) 1128 concurrent sessions 215 session/s (avg: 223 ) 1136 concurrent sessions 206 session/s (avg: 221 ) 1140 concurrent sessions
79 lines
1.7 KiB
Bash
79 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
## contrib by prizee.com
|
|
|
|
socket='/var/run/haproxy.stat'
|
|
|
|
if ! type socat >/dev/null 2>&1 ; then
|
|
echo "can't find socat in PATH" 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
printUsage ()
|
|
{
|
|
echo -e "Usage : $(basename $0) [options] -s section
|
|
--section -s section\t: section to use ( --list format)
|
|
Options :
|
|
--socket -S [socket]\t: socket to use (default: /var/run/haproxy.stat)
|
|
--list -l\t\t: print available sections
|
|
--help -h\t\t: print this message"
|
|
}
|
|
|
|
getRawStat ()
|
|
{
|
|
if [ ! -S $socket ] ; then
|
|
echo "$socket socket unavailable" 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! printf "show stat\n" | socat unix-connect:${socket} stdio | grep -v "^#" ; then
|
|
echo "cannot read $socket" 1>&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
getStat ()
|
|
{
|
|
stats=$(getRawStat | grep $1 | awk -F "," '{print $5" "$8}')
|
|
export cumul=$(echo $stats | cut -d " " -f2)
|
|
export current=$(echo $stats | cut -d " " -f1)
|
|
}
|
|
|
|
showList ()
|
|
{
|
|
getRawStat | awk -F "," '{print $1","$2}'
|
|
}
|
|
|
|
set -- `getopt -u -l socket:,section:,list,help -- s:S:lh "$@"`
|
|
|
|
while true ; do
|
|
case $1 in
|
|
--socket|-S) socket=$2 ; shift 2 ;;
|
|
--section|-s) section=$2 ; shift 2 ;;
|
|
--help|-h) printUsage ; exit 0 ;;
|
|
--list|-l) showList ; exit 0 ;;
|
|
--) break ;;
|
|
esac
|
|
done
|
|
|
|
if [ "$section" = "" ] ; then
|
|
echo "section not specified, run '$(basename $0) --list' to know available sections" 1>&2
|
|
printUsage
|
|
exit 1
|
|
fi
|
|
|
|
cpt=0
|
|
totalrate=0
|
|
while true ; do
|
|
getStat $section
|
|
if [ "$cpt" -gt "0" ] ; then
|
|
sessionrate=$(($cumul-$oldcumul))
|
|
totalrate=$(($totalrate+$sessionrate))
|
|
averagerate=$(($totalrate/$cpt))
|
|
printf "$sessionrate sessions/s (avg: $averagerate )\t$current concurrent sessions\n"
|
|
fi
|
|
oldcumul=$cumul
|
|
sleep 1
|
|
cpt=$(($cpt+1))
|
|
done
|