Projet

Général

Profil

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

root / plugins / haproxy / haproxy_sessions_backend @ 17f78427

Historique | Voir | Annoter | Télécharger (3,75 ko)

1
#!/bin/bash
2
# -*- bash -*-
3

    
4
: << =cut
5

    
6
=head1 NAME
7

    
8
haproxy_sessions_backend -Haproxy Sessions Backend
9

    
10
=head1 CONFIGURATION
11

    
12
[haproxy*]
13
  user root
14
  env.backend backend_name_1 backend_name_2 backend_name_3
15
  env.frontend frontend_name_1 frontend_name_2 frontend_name_3
16
  # You can use url o socket option, use one of them, not both!
17
    env.url  http://user:passwd@IP:port/admin?stats;csv
18
  #  or
19
    env.socket /var/lib/haproxy/stats.socket
20

    
21
=head1 AUTHOR
22

    
23
Ricardo Fraile <rfrail3@yahoo.es>
24

    
25
=head1 LICENSE
26

    
27
GPLv2
28

    
29
=head1 MAGICK MARKERS
30

    
31
 #%# family=auto
32
 #%# capabilities=autoconf
33

    
34
=cut
35

    
36
. $MUNIN_LIBDIR/plugins/plugin.sh
37

    
38
function parse_url {
39
        # Modify ifs variable
40
        OIFS=$IFS;
41
        IFS=",";
42
        PXNAME="$1"
43
        SVNAME="$2"
44
        VALUE="$3"
45

    
46
        if [ ! -z "$url" ]; then
47
                LINE1=`curl -s "$url" | head -1 | sed 's/# //'`
48
                LINE2=`curl -s "$url" | grep "$PXNAME,$SVNAME"`
49
        fi
50

    
51
        if [ ! -z "$socket" ]; then
52
                LINE1=`echo 'show stat' | socat unix-connect:"$socket" stdio | head -1 | sed 's/# //'`
53
                LINE2=`echo 'show stat' | socat unix-connect:"$socket" stdio | grep "$PXNAME,$SVNAME"`
54
        fi
55

    
56
        ARRAY1=($LINE1);
57

    
58
        # Find values
59
        for ((i=0; i<${#ARRAY1[@]}; ++i));
60
        do
61
                # Get data
62
                if [[ "${ARRAY1[$i]}" == "${VALUE}" ]]; then
63
                        o=$i;
64
                        o=`expr $o + 1`
65
                        echo ${LINE2} | cut -d" " -f $o
66
                fi
67
        done
68

    
69
        # Reset ifs
70
        IFS=$OIFS;
71
}
72

    
73

    
74
SVNAME='BACKEND'
75
LIST="$backend"
76
WARN_PERCENT="80"
77

    
78

    
79
if [ "$1" = "autoconf" ]; then
80
	echo yes
81
	exit 0
82
fi
83

    
84
if [ "$1" = "config" ]; then
85

    
86
	echo "graph_title Current sessions ${SVNAME}"
87
	echo 'graph_args --base 1000 -l 0 '
88
	echo 'graph_vlabel Sessions'
89
	echo 'graph_scale no'
90
	echo 'graph_category loadbalancer'
91
	echo "graph_info Current sessions ${SVNAME}"
92

    
93

    
94
	for i in ${LIST}; do
95
	        echo "scur`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label Current Sessions $i"
96
        	echo "scur`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type GAUGE"
97
	        echo "scur`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
98
        	echo "scur`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info Current Sessions $i"
99

    
100
	        #echo "smax`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label Max $i"
101
        	#echo "smax`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type GAUGE"
102
	        #echo "smax`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
103
        	#echo "smax`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info Max sessions $i"
104

    
105
	        echo "slim`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label Limit Sessions  $i"
106
        	echo "slim`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type GAUGE"
107
	        echo "slim`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
108
        	echo "slim`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info Limit Sessions $i"
109

    
110
		SLIM=`parse_url ${i} ${SVNAME} slim`
111
                if [[ "$SLIM" =~ ^[0-9]+$ ]] && [[ "$SLIM" != 0 ]]; then
112
                   echo "scur`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.critical $SLIM"
113
                fi
114
                if [[ "$SLIM" =~ ^[0-9]+$ ]] && [[ "$SLIM" != 0 ]]; then
115
                        echo "scur`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.warning $((${SLIM}*${WARN_PERCENT}/100))"
116
                fi
117
	done
118

    
119
	exit 0
120
fi
121
	for i in ${LIST}; do
122
		SCUR=`parse_url ${i} ${SVNAME} scur`
123
		#SMAX=`parse_url ${i} ${SVNAME} smax`
124
		SLIM=`parse_url ${i} ${SVNAME} slim`
125

    
126
	        echo "scur`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $SCUR"
127
        	#echo "smax`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $SMAX"
128
        	echo "slim`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $SLIM"
129
	done
130

    
131