Projet

Général

Profil

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

root / plugins / ipvs / ipvs_active @ ef960abc

Historique | Voir | Annoter | Télécharger (1,85 ko)

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

    
4
: << =cut
5

    
6
=head1 NAME
7

    
8
ipvs_conn -Indicate the number of active servers in ipvs
9

    
10
=head1 CONFIGURATION
11

    
12
[ipvs_*]
13
user root
14
env.ips IP1 IP2
15

    
16
=head1 AUTHOR
17

    
18
Ricardo Fraile <rfrail3@yahoo.es>
19

    
20
=head1 LICENSE
21

    
22
GPLv2
23

    
24
=head1 MAGICK MARKERS
25

    
26
 #%# family=auto
27
 #%# capabilities=autoconf
28

    
29
=cut
30

    
31
. $MUNIN_LIBDIR/plugins/plugin.sh
32

    
33

    
34
IPLIST=$ips
35

    
36

    
37
if [ "$1" = "autoconf" ]; then
38
        echo yes 
39
        exit 0
40
fi
41

    
42
if [ "$1" = "config" ]; then
43

    
44
        echo 'graph_title Ipvs Active Servers'
45
        echo 'graph_args --base 1000 -l 0 '
46
        echo 'graph_vlabel Servers'
47
        echo 'graph_scale no'
48
        echo 'graph_category Ipvs'
49
        echo 'graph_info Indicate the number of active servers in Ipvs.'
50

    
51
	for IP in $IPLIST; do
52
		NM=`echo $IP | md5sum | cut -d - -f1 | sed 's/ //g' | cut -b 5-9`
53
	        echo "a$NM.label $IP Active"
54
        	echo "a$NM.type GAUGE"
55
	        echo "a$NM.min 0"
56
	done
57

    
58
        exit 0
59
fi
60

    
61

    
62

    
63
# Get line number of match listen ip
64
function get_ip {
65
# Read the output
66
ipvsadm -l -n | nl | while read line; do
67
	# If match the ip, print the line number	
68
	if ( echo $line | grep -e $IP > /dev/null ); then
69
		MAT=`echo $line | cut -d " " -f 1`
70
		echo $MAT
71
	fi
72
done
73
}
74

    
75

    
76
for IP in $IPLIST; do
77

    
78
	COUNT="0"
79
	ACTCONCNT="0"
80
	INACTCONCNT="0"
81
	F1=`mktemp`
82
	MATCH=`get_ip`
83
	ipvsadm -l -n | nl > $F1
84

    
85
	# Parse lines
86
	while read line; do
87
	
88
		# Get line numbers
89
		N=`echo $line | cut -d " " -f 1`
90

    
91
		# If line number match the line number of the match listen ip, print the line...
92
		if [ "$N" -gt "$MATCH" ]; then
93
			# ... except if the line contain TCP or UDP word (this start an other listen)
94
			if ( echo $line | grep -e TCP -e UDP > /dev/null ); then
95
				break
96
			fi
97
		
98
			COUNT=`expr $COUNT + 1`
99
		fi
100
	done < $F1
101

    
102

    
103
	# Print values
104
	NM=`echo $IP | md5sum | cut -d - -f1 | sed 's/ //g' | cut -b 5-9`
105
	echo a$NM.value $COUNT
106

    
107
	# Remove temp file
108
	rm -f $F1
109
done