Projet

Général

Profil

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

root / plugins / haproxy / haproxy_active_backend @ 09b88141

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

1 706e7e91 ricardo
#!/bin/bash
2
# -*- bash -*-
3
4
: << =cut
5
6
=head1 NAME
7
8
haproxy_active_backend -Haproxy servers active backend
9
10
=head1 CONFIGURATION
11
12 09b88141 Lars Kruse
  [haproxy*]
13 706e7e91 ricardo
  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 4f29ff59 rfrail3
  # 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 706e7e91 ricardo
21
=head1 AUTHOR
22
23
Ricardo Fraile <rfrail3@yahoo.es>
24
25
=head1 LICENSE
26
27 a717a913 rfrail3
GPLv2
28 706e7e91 ricardo
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 4f29ff59 rfrail3
	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 706e7e91 ricardo
	ARRAY1=($LINE1);
56
57
	# Find values
58
	for ((i=0; i<${#ARRAY1[@]}; ++i));
59
	do
60
        	# Get data
61
	        if [[ "${ARRAY1[$i]}" == "${VALUE}" ]]; then
62
	                o=$i;
63
        	        o=`expr $o + 1`
64
                	echo ${LINE2} | cut -d" " -f $o
65
	        fi
66
	done
67
68
	# Reset ifs
69
	IFS=$OIFS;
70
}
71
72
73
SVNAME='BACKEND'
74
LIST=$backend
75
76
if [ "$1" = "autoconf" ]; then
77 17f78427 Lars Kruse
	echo yes
78 706e7e91 ricardo
	exit 0
79
fi
80
81
if [ "$1" = "config" ]; then
82
83
	echo "graph_title Active Servers ${SVNAME}"
84
	echo 'graph_args --base 1000 -l 0 '
85
	echo 'graph_vlabel Servers'
86
	echo 'graph_scale no'
87 a3c2338b dipohl
	echo 'graph_category loadbalancer'
88 706e7e91 ricardo
	echo "graph_info Active Servers ${SVNAME}"
89
90
	for i in ${LIST}; do
91
	        echo "act`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label Active Servers $i"
92
        	echo "act`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type GAUGE"
93
	        echo "act`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
94
        	echo "act`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info Active Servers $i"
95
	done
96
97
	exit 0
98
fi
99
	for i in ${LIST}; do
100
		ACT=`parse_url ${i} ${SVNAME} act`
101
	        echo "act`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $ACT"
102
	done