1#!/usr/local/bin/bash 2# -*- bash -*- 3 4: << =cut 5 6=head1 NAME 7 8ipvs_conn -Indicate the number of connections in ipvs 9 10=head1 CONFIGURATION 11 12 [ipvs_*] 13 user root 14 env.ips IP1 IP2 15 16=head1 AUTHOR 17 18Ricardo Fraile <rfrail3@yahoo.es> 19 20=head1 LICENSE 21 22GPLv2 23 24=head1 MAGICK MARKERS 25 26 #%# family=auto 27 #%# capabilities=autoconf 28 29=cut 30 31. $MUNIN_LIBDIR/plugins/plugin.sh 32 33 34IPLIST=$ips 35 36 37if [ "$1" = "autoconf" ]; then 38 echo yes 39 exit 0 40fi 41 42if [ "$1" = "config" ]; then 43 44 echo 'graph_title Ipvs Connections' 45 echo 'graph_args --base 1000 -l 0 ' 46 echo 'graph_vlabel Connections' 47 echo 'graph_scale no' 48 echo 'graph_category loadbalancer' 49 echo 'graph_info Indicate the number of active and inactive connections 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 ActiveConn" 54 echo "a$NM.type GAUGE" 55 echo "a$NM.min 0" 56 echo "i$NM.label $IP InActiveConn" 57 echo "i$NM.type GAUGE" 58 echo "i$NM.min 0" 59 done 60 61 exit 0 62fi 63 64 65 66# Get line number of match listen ip 67function get_ip { 68# Read the output 69ipvsadm -l -n | nl | while read line; do 70 # If match the ip, print the line number 71 if ( echo $line | grep -e $IP > /dev/null ); then 72 MAT=`echo $line | cut -d " " -f 1` 73 echo $MAT 74 fi 75done 76} 77 78 79for IP in $IPLIST; do 80 81 COUNT="0" 82 ACTCONCNT="0" 83 INACTCONCNT="0" 84 F1=`mktemp` 85 MATCH=`get_ip` 86 ipvsadm -l -n | nl > $F1 87 88 # Parse lines 89 while read line; do 90 91 # Get line numbers 92 N=`echo $line | cut -d " " -f 1` 93 94 # If line number match the line number of the match listen ip, print the line... 95 if [ "$N" -gt "$MATCH" ]; then 96 # ... except if the line contain TCP or UDP word (this start an other listen) 97 if ( echo $line | grep -e TCP -e UDP > /dev/null ); then 98 break 99 fi 100 101 # Get ActiveConn number 102 NUM1=`echo $line | awk '{print $6}'` 103 # Sum it 104 ACTCONCNT=$(( ACTCONCNT + NUM1)) 105 # Get InActConn number 106 NUM2=`echo $line | awk '{print $7}'` 107 # Sum it 108 INACTCONCNT=$(( INACTCONCNT + NUM2)) 109 110 COUNT=`expr $COUNT + 1` 111 fi 112 done < $F1 113 114 115 # Print values 116 NM=`echo $IP | md5sum | cut -d - -f1 | sed 's/ //g' | cut -b 5-9` 117 echo a$NM.value $(( ACTCONCNT / COUNT )) 118 echo i$NM.value $(( INACTCONCNT / COUNT )) 119 120 # Remove temp file 121 rm -f $F1 122done 123