From 825cb21450789a155feb8f22bc345ab3b1a5d71e Mon Sep 17 00:00:00 2001 From: Allan Parsons Date: Tue, 30 Jul 2013 13:21:01 -0700 Subject: [PATCH 1/4] Update haproxy-sessions-by-servers Updated haproxy-sessions-by-servers to look at the current sessions by individual servers. I believe this was the original intent of the script (it was broken by default when symlinking it in /etc/munin/plugins/ (/etc/munin/plugins/haproxy-sessions-by-servers). NOW SUPPORTS: - URL + Socket Stats - Dynamic list of individual backend member servers - tested / works with munin-node NUANCES: - may be annoying with an absurd number of backend member nodes (I have 10 on this particular haproxy instance) --- plugins/haproxy/haproxy-sessions-by-servers | 126 +++++++++++++++----- 1 file changed, 96 insertions(+), 30 deletions(-) diff --git a/plugins/haproxy/haproxy-sessions-by-servers b/plugins/haproxy/haproxy-sessions-by-servers index 548a2ae0..816fb9e9 100755 --- a/plugins/haproxy/haproxy-sessions-by-servers +++ b/plugins/haproxy/haproxy-sessions-by-servers @@ -1,45 +1,111 @@ -#!/bin/sh -# Pasha "p01nt" Klets +#!/bin/bash +# Allan Parsons (allan.parsons@gmail.com) + +##DEBUGDEBUG +#MUNIN_LIBDIR=/usr/share/munin +#. $MUNIN_LIBDIR/plugins/plugin.sh +#socket="/var/run/haproxy.sock" + + name=`basename $0` title=`echo ${name} | awk -F_ '{print $NF}'` +SVNAME='BACKEND' +LIST=$backend -hp_stat() { - echo "show stat" | socat unix-connect:/tmp/haproxy stdio + + +function parse_url { + # Modify ifs variable + OIFS=$IFS; + IFS=","; + PXNAME="$1" + SVNAME="$2" + VALUE="$3" + if [ ! -z "$4" ]; then + SERVERNAME="$4" + fi + + if [ ! -z "$url" ]; then + LINE1=`curl -s "$url" | head -1 | sed 's/# //'` + LINE2=`curl -s "$url" | grep "$PXNAME,$SVNAME"` + fi + + if [ ! -z "$socket" ]; then + LINE1=`echo "show stat" | socat unix-connect:"$socket" stdio | head -1 | sed 's/# //'` + LINE2=`echo "show stat" | socat unix-connect:"$socket" stdio | grep "$PXNAME" | grep -v "$PXNAME,$SVNAME" | tr ',' ' '` + + CMD="echo show stat | socat unix-connect:$socket stdio | grep $PXNAME | grep -v PXNAME,$SVNAME" + #echo $CMD + #exit + fi + + + ARRAY1=($LINE1); + if [ ! -z $SERVERNAME ]; then + # Find values + for ((i=0; i<${#ARRAY1[@]}; ++i)); + do + # Get data + if [[ "${ARRAY1[$i]}" == "${VALUE}" ]]; then + o=$i; + o=`expr $o + 1` + RVAL=`echo ${LINE2} | grep ${SERVERNAME} | cut -d" " -f $o` + fi + done + else + RVAL=`echo 'show stat' | socat unix-connect:"$socket" stdio | grep "$PXNAME" | grep -v "$PXNAME,$SVNAME" | tr ',' ' ' | awk '{print $2}'` + fi + # Reset ifs + IFS=$OIFS; + + ## return val + echo $RVAL } -servers_section() { - hp_stat | grep '^'${title}',' | egrep -v '^'${title}',(FRONTEND|BACKEND)' -} -servers() { - servers_section | awk -F, '{print $2}' -} -labels() { - servers_section | awk -F, '{print $2".label "$2"\n"$2".type GAUGE\n"$2".draw AREASTACK"}' -} - -values() { - servers_section | awk -F, '{print $2".value "$5}' -} +## +## Main +## graph_title="${title} sessions by servers" graph_vlabel=${title} -case $1 in - config) - cat < Date: Tue, 30 Jul 2013 13:22:13 -0700 Subject: [PATCH 2/4] Update haproxy-sessions-by-servers - Minor update to oversight for creating a filtered list for url parsing as opposed to socket parsing. --- plugins/haproxy/haproxy-sessions-by-servers | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/haproxy/haproxy-sessions-by-servers b/plugins/haproxy/haproxy-sessions-by-servers index 816fb9e9..896a3e05 100755 --- a/plugins/haproxy/haproxy-sessions-by-servers +++ b/plugins/haproxy/haproxy-sessions-by-servers @@ -28,14 +28,13 @@ function parse_url { if [ ! -z "$url" ]; then LINE1=`curl -s "$url" | head -1 | sed 's/# //'` - LINE2=`curl -s "$url" | grep "$PXNAME,$SVNAME"` + LINE2=`curl -s "$url" | grep "$PXNAME" | grep -v "$PXNAME,$SVNAME" | tr ',' ' '` fi if [ ! -z "$socket" ]; then LINE1=`echo "show stat" | socat unix-connect:"$socket" stdio | head -1 | sed 's/# //'` LINE2=`echo "show stat" | socat unix-connect:"$socket" stdio | grep "$PXNAME" | grep -v "$PXNAME,$SVNAME" | tr ',' ' '` - CMD="echo show stat | socat unix-connect:$socket stdio | grep $PXNAME | grep -v PXNAME,$SVNAME" #echo $CMD #exit fi From 2e950fcd2f818ddf6275a74cfe28b6c6da20627d Mon Sep 17 00:00:00 2001 From: Allan Parsons Date: Tue, 30 Jul 2013 13:55:29 -0700 Subject: [PATCH 3/4] Update haproxy-sessions-by-servers Fixed issue with number formatting. Graph_printf doesn't seem to be working... so graphs aren't updating. --- plugins/haproxy/haproxy-sessions-by-servers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/haproxy/haproxy-sessions-by-servers b/plugins/haproxy/haproxy-sessions-by-servers index 896a3e05..da28360e 100755 --- a/plugins/haproxy/haproxy-sessions-by-servers +++ b/plugins/haproxy/haproxy-sessions-by-servers @@ -82,7 +82,7 @@ if [ "$1" = "config" ]; then echo "graph_category haproxy" echo "graph_title ${graph_title}" echo "graph_vlabel ${graph_vlabel}" - echo "graph_printf %.0f" + #echo "graph_printf %.0f" for i in ${LIST}; do SERVERLIST=$(parse_url ${i} ${SVNAME} svname) From 41db1b552bb7653934375331b20f43a8dfe6df8b Mon Sep 17 00:00:00 2001 From: Allan Parsons Date: Tue, 10 Dec 2013 22:07:28 +0000 Subject: [PATCH 4/4] Update haproxy-sessions-by-servers --- plugins/haproxy/haproxy-sessions-by-servers | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/haproxy/haproxy-sessions-by-servers b/plugins/haproxy/haproxy-sessions-by-servers index da28360e..d731ad1a 100755 --- a/plugins/haproxy/haproxy-sessions-by-servers +++ b/plugins/haproxy/haproxy-sessions-by-servers @@ -1,5 +1,9 @@ #!/bin/bash # Allan Parsons (allan.parsons@gmail.com) +# This was a rewrite by Allan Parsons +# +# Original Author: Pasha "p01nt" Klets +# ##DEBUGDEBUG #MUNIN_LIBDIR=/usr/share/munin