3
## contrib by prizee.com
5
socket='/var/run/haproxy.stat'
7
if ! type socat >/dev/null 2>&1 ; then
8
echo "can't find socat in PATH" 1>&2
14
echo -e "Usage : $(basename $0) [options] -s section
15
--section -s section\t: section to use ( --list format)
17
--socket -S [socket]\t: socket to use (default: /var/run/haproxy.stat)
18
--list -l\t\t: print available sections
19
--help -h\t\t: print this message"
24
if [ ! -S $socket ] ; then
25
echo "$socket socket unavailable" 1>&2
29
if ! printf "show stat\n" | socat unix-connect:${socket} stdio | grep -v "^#" ; then
30
echo "cannot read $socket" 1>&2
37
stats=$(getRawStat | grep $1 | awk -F "," '{print $5" "$8}')
38
export cumul=$(echo $stats | cut -d " " -f2)
39
export current=$(echo $stats | cut -d " " -f1)
44
getRawStat | awk -F "," '{print $1","$2}'
47
set -- `getopt -u -l socket:,section:,list,help -- s:S:lh "$@"`
51
--socket|-S) socket=$2 ; shift 2 ;;
52
--section|-s) section=$2 ; shift 2 ;;
53
--help|-h) printUsage ; exit 0 ;;
54
--list|-l) showList ; exit 0 ;;
59
if [ "$section" = "" ] ; then
60
echo "section not specified, run '$(basename $0) --list' to know available sections" 1>&2
69
if [ "$cpt" -gt "0" ] ; then
70
sessionrate=$(($cumul-$oldcumul))
71
totalrate=$(($totalrate+$sessionrate))
72
averagerate=$(($totalrate/$cpt))
73
printf "$sessionrate sessions/s (avg: $averagerate )\t$current concurrent sessions\n"