Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / haproxy / haproxy-sessions-by-servers @ 2e950fcd

Historique | Voir | Annoter | Télécharger (2,6 ko)

1 825cb214 Allan Parsons
#!/bin/bash
2
# Allan Parsons (allan.parsons@gmail.com)
3
4
##DEBUGDEBUG
5
#MUNIN_LIBDIR=/usr/share/munin
6
#. $MUNIN_LIBDIR/plugins/plugin.sh
7
#socket="/var/run/haproxy.sock"
8
9
10 8b63e3cd Pasha Klets
11
name=`basename $0`
12
title=`echo ${name} | awk -F_ '{print $NF}'`
13 825cb214 Allan Parsons
SVNAME='BACKEND'
14
LIST=$backend
15 8b63e3cd Pasha Klets
16
17
18 825cb214 Allan Parsons
function parse_url {
19
	# Modify ifs variable
20
	OIFS=$IFS;
21
	IFS=",";
22
	PXNAME="$1"
23
	SVNAME="$2"
24
	VALUE="$3"
25
	if [ ! -z "$4" ]; then
26
	   SERVERNAME="$4"
27
	fi
28
29
        if [ ! -z "$url" ]; then
30
                LINE1=`curl -s "$url" | head -1 | sed 's/# //'`
31 7b888282 Allan Parsons
                LINE2=`curl -s "$url" | grep "$PXNAME" | grep -v "$PXNAME,$SVNAME" | tr ',' ' '`
32 825cb214 Allan Parsons
        fi
33
34
        if [ ! -z "$socket" ]; then
35
                LINE1=`echo "show stat" | socat unix-connect:"$socket" stdio | head -1 | sed 's/# //'`
36
                LINE2=`echo "show stat" | socat unix-connect:"$socket" stdio | grep "$PXNAME" | grep -v "$PXNAME,$SVNAME" | tr ',' ' '`
37
38
		#echo $CMD
39
		#exit
40
        fi
41 8b63e3cd Pasha Klets
42
43 825cb214 Allan Parsons
	ARRAY1=($LINE1);
44
	if [ ! -z $SERVERNAME ]; then
45
		# Find values
46
		for ((i=0; i<${#ARRAY1[@]}; ++i));
47
		do
48
	        	# Get data
49
		        if [[ "${ARRAY1[$i]}" == "${VALUE}" ]]; then
50
		                o=$i;
51
	        	        o=`expr $o + 1`
52
				RVAL=`echo ${LINE2} | grep ${SERVERNAME} | cut -d" " -f $o`
53
		        fi
54
		done
55
	else
56
		RVAL=`echo 'show stat' | socat unix-connect:"$socket" stdio | grep "$PXNAME" | grep -v "$PXNAME,$SVNAME" | tr ',' ' ' | awk '{print $2}'`
57
	fi
58
	# Reset ifs
59
	IFS=$OIFS;
60
61
	## return val
62
	echo $RVAL
63 8b63e3cd Pasha Klets
}
64
65 825cb214 Allan Parsons
66
67
##
68
## Main
69
##
70
71 8b63e3cd Pasha Klets
graph_title="${title} sessions by servers"
72
graph_vlabel=${title}
73
74 825cb214 Allan Parsons
if [ "$1" = "autoconf" ]; then
75
	echo yes 
76
	exit 0
77
fi
78
79
80
if [ "$1" = "config" ]; then
81
82
	echo "graph_category haproxy"
83
	echo "graph_title  ${graph_title}"
84
	echo "graph_vlabel ${graph_vlabel}"
85 2e950fcd Allan Parsons
	#echo "graph_printf %.0f"
86 825cb214 Allan Parsons
87
	for i in ${LIST}; do
88
		SERVERLIST=$(parse_url ${i} ${SVNAME} svname)
89
		for s in $SERVERLIST; do
90
	        echo "hsessionsbyservers_$s_`echo $i_$s | md5sum | cut -d - -f1 | sed 's/ //g'`.label $s"
91
        	echo "hsessionsbyservers_$s_`echo $i_$s | md5sum | cut -d - -f1 | sed 's/ //g'`.type DERIVE"
92
			echo "hsessionsbyservers_$s_`echo $i_$s | md5sum | cut -d - -f1 | sed 's/ //g'`.info Active Sessions for $s"
93
			echo "hsessionsbyservers_$s_`echo $i_$s | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
94
			#echo "hsessionsbyservers_$s_`echo $i_$s | md5sum | cut -d - -f1 | sed 's/ //g'`.draw AREASTACK"
95
        done
96
    done
97
98
    exit 0
99
fi
100
101 8b63e3cd Pasha Klets
102 825cb214 Allan Parsons
for i in ${LIST}; do
103 8b63e3cd Pasha Klets
104 825cb214 Allan Parsons
	SERVERLIST=$(parse_url ${i} ${SVNAME} svname)
105 8b63e3cd Pasha Klets
106 825cb214 Allan Parsons
	for s in $SERVERLIST; do
107
		val=$(parse_url ${i} ${SVNAME} scur ${s})
108
        echo "hsessionsbyservers_$s_`echo $i_$s | md5sum| cut -d - -f1 | sed 's/ //g'`.value ${val}"
109
    done
110
done