Projet

Général

Profil

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

root / plugins / haproxy / haproxy_rate_backend @ 706e7e91

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

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

    
4
: << =cut
5

    
6
=head1 NAME
7

    
8
haproxy_rate_backend -Haproxy Sessions Per Second 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
  env.url  http://user:passwd@IP:port/admin?stats;csv
17

    
18
=head1 AUTHOR
19

    
20
Ricardo Fraile <rfrail3@yahoo.es>
21

    
22
=head1 LICENSE
23

    
24
GNU
25

    
26
=head1 MAGICK MARKERS
27

    
28
 #%# family=auto
29
 #%# capabilities=autoconf
30

    
31
=cut
32

    
33
. $MUNIN_LIBDIR/plugins/plugin.sh
34

    
35
function parse_url {
36
        # Modify ifs variable
37
        OIFS=$IFS;
38
        IFS=",";
39
        PXNAME="$1"
40
        SVNAME="$2"
41
        VALUE="$3"
42
        LINE1=`curl -s "$url" | head -1 | sed 's/# //'`
43
        LINE2=`curl -s "$url" | grep "$PXNAME,$SVNAME"`
44
        
45
        
46
        ARRAY1=($LINE1);
47

    
48
        # Find values
49
        for ((i=0; i<${#ARRAY1[@]}; ++i));
50
        do
51
                # Get data
52
                if [[ "${ARRAY1[$i]}" == "${VALUE}" ]]; then
53
                        o=$i;
54
                        o=`expr $o + 1`
55
                        echo ${LINE2} | cut -d" " -f $o
56
                fi
57
        done
58

    
59
        # Reset ifs
60
        IFS=$OIFS;
61
}
62

    
63

    
64
SVNAME='BACKEND'
65
LIST=$backend
66

    
67
if [ "$1" = "autoconf" ]; then
68
	echo yes 
69
	exit 0
70
fi
71

    
72
if [ "$1" = "config" ]; then
73

    
74
	echo "graph_title Sessions per second ${SVNAME}"
75
	echo 'graph_args --base 1000 -l 0 '
76
	echo 'graph_vlabel Sessions'
77
	echo 'graph_scale no'
78
	echo 'graph_category haproxy'
79
	echo "graph_info Sessions per second ${SVNAME}"
80

    
81

    
82
	for i in ${LIST}; do
83
	        echo "rate`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label Rate $i"
84
        	echo "rate`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type GAUGE"
85
	        echo "rate`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
86
        	echo "rate`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info Number of sessions per second over last elapsed second $i"
87

    
88
	        echo "rate_lim`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label Limit $i"
89
        	echo "rate_lim`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type GAUGE"
90
	        echo "rate_lim`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
91
        	echo "rate_lim`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info Limit on new sessions per second $i"
92

    
93
	        #echo "rate_max`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label Max $i"
94
        	#echo "rate_max`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type GAUGE"
95
	        #echo "rate_max`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
96
        	#echo "rate_max`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info Max number of new sessions per second $i"
97

    
98
	done
99

    
100
	exit 0
101
fi
102
	for i in ${LIST}; do
103
	 	RATE=`parse_url ${i} ${SVNAME} rate`
104
		RATEL=`parse_url ${i} ${SVNAME} rate_lim`
105
		#RATEM=`parse_url ${i} ${SVNAME} rate_max`
106

    
107
	        echo "rate`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $RATE"
108
        	echo "rate_lim`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $RATEL"
109
        	#echo "rate_max`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $RATEM"
110
	done
111
	
112