2012-10-22 12:32:51 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# -*- bash -*-
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
ipvs_conn -Indicate the number of connections in ipvs
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
[ipvs_*]
|
|
|
|
user root
|
|
|
|
env.ips IP1 IP2
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Ricardo Fraile <rfrail3@yahoo.es>
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
GPLv2
|
|
|
|
|
|
|
|
=head1 MAGICK MARKERS
|
|
|
|
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
. $MUNIN_LIBDIR/plugins/plugin.sh
|
|
|
|
|
|
|
|
|
|
|
|
IPLIST=$ips
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
2018-08-02 02:03:42 +02:00
|
|
|
echo yes
|
2012-10-22 12:32:51 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
|
|
|
|
echo 'graph_title Ipvs Connections'
|
|
|
|
echo 'graph_args --base 1000 -l 0 '
|
|
|
|
echo 'graph_vlabel Connections'
|
|
|
|
echo 'graph_scale no'
|
2017-02-22 05:34:14 +01:00
|
|
|
echo 'graph_category loadbalancer'
|
2012-10-22 12:32:51 +02:00
|
|
|
echo 'graph_info Indicate the number of active and inactive connections in Ipvs.'
|
|
|
|
|
|
|
|
for IP in $IPLIST; do
|
|
|
|
NM=`echo $IP | md5sum | cut -d - -f1 | sed 's/ //g' | cut -b 5-9`
|
|
|
|
echo "a$NM.label $IP ActiveConn"
|
|
|
|
echo "a$NM.type GAUGE"
|
|
|
|
echo "a$NM.min 0"
|
|
|
|
echo "i$NM.label $IP InActiveConn"
|
|
|
|
echo "i$NM.type GAUGE"
|
|
|
|
echo "i$NM.min 0"
|
|
|
|
done
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get line number of match listen ip
|
|
|
|
function get_ip {
|
|
|
|
# Read the output
|
|
|
|
ipvsadm -l -n | nl | while read line; do
|
2018-08-02 02:03:42 +02:00
|
|
|
# If match the ip, print the line number
|
2012-10-22 12:32:51 +02:00
|
|
|
if ( echo $line | grep -e $IP > /dev/null ); then
|
|
|
|
MAT=`echo $line | cut -d " " -f 1`
|
|
|
|
echo $MAT
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for IP in $IPLIST; do
|
|
|
|
|
|
|
|
COUNT="0"
|
|
|
|
ACTCONCNT="0"
|
|
|
|
INACTCONCNT="0"
|
|
|
|
F1=`mktemp`
|
|
|
|
MATCH=`get_ip`
|
|
|
|
ipvsadm -l -n | nl > $F1
|
|
|
|
|
|
|
|
# Parse lines
|
|
|
|
while read line; do
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2012-10-22 12:32:51 +02:00
|
|
|
# Get line numbers
|
|
|
|
N=`echo $line | cut -d " " -f 1`
|
|
|
|
|
|
|
|
# If line number match the line number of the match listen ip, print the line...
|
|
|
|
if [ "$N" -gt "$MATCH" ]; then
|
2013-06-17 11:49:31 +02:00
|
|
|
# ... except if the line contain TCP or UDP word (this start an other listen)
|
|
|
|
if ( echo $line | grep -e TCP -e UDP > /dev/null ); then
|
2012-10-22 12:32:51 +02:00
|
|
|
break
|
|
|
|
fi
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2012-10-22 12:32:51 +02:00
|
|
|
# Get ActiveConn number
|
|
|
|
NUM1=`echo $line | awk '{print $6}'`
|
|
|
|
# Sum it
|
|
|
|
ACTCONCNT=$(( ACTCONCNT + NUM1))
|
|
|
|
# Get InActConn number
|
|
|
|
NUM2=`echo $line | awk '{print $7}'`
|
|
|
|
# Sum it
|
|
|
|
INACTCONCNT=$(( INACTCONCNT + NUM2))
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2012-10-22 12:32:51 +02:00
|
|
|
COUNT=`expr $COUNT + 1`
|
|
|
|
fi
|
|
|
|
done < $F1
|
|
|
|
|
|
|
|
|
|
|
|
# Print values
|
|
|
|
NM=`echo $IP | md5sum | cut -d - -f1 | sed 's/ //g' | cut -b 5-9`
|
|
|
|
echo a$NM.value $(( ACTCONCNT / COUNT ))
|
|
|
|
echo i$NM.value $(( INACTCONCNT / COUNT ))
|
|
|
|
|
|
|
|
# Remove temp file
|
|
|
|
rm -f $F1
|
|
|
|
done
|