From 5e94465b62996170b39a2038941538ae36a3935d Mon Sep 17 00:00:00 2001 From: rfrail3 Date: Mon, 22 Oct 2012 12:32:51 +0200 Subject: [PATCH] plugin for monitor ipvs --- plugins/ipvs/ipvs_active | 109 ++++++++++++++++++++++++++++++++++ plugins/ipvs/ipvs_bps | 87 ++++++++++++++++++++++++++++ plugins/ipvs/ipvs_conn | 122 +++++++++++++++++++++++++++++++++++++++ plugins/ipvs/ipvs_cps | 76 ++++++++++++++++++++++++ 4 files changed, 394 insertions(+) create mode 100755 plugins/ipvs/ipvs_active create mode 100755 plugins/ipvs/ipvs_bps create mode 100755 plugins/ipvs/ipvs_conn create mode 100755 plugins/ipvs/ipvs_cps diff --git a/plugins/ipvs/ipvs_active b/plugins/ipvs/ipvs_active new file mode 100755 index 00000000..87a04099 --- /dev/null +++ b/plugins/ipvs/ipvs_active @@ -0,0 +1,109 @@ +#!/bin/bash +# -*- bash -*- + +: << =cut + +=head1 NAME + +ipvs_conn -Indicate the number of active servers in ipvs + +=head1 CONFIGURATION + +[ipvs_*] +user root +env.ips IP1 IP2 + +=head1 AUTHOR + +Ricardo Fraile + +=head1 LICENSE + +GPLv2 + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + + +IPLIST=$ips + + +if [ "$1" = "autoconf" ]; then + echo yes + exit 0 +fi + +if [ "$1" = "config" ]; then + + echo 'graph_title Ipvs Active Servers' + echo 'graph_args --base 1000 -l 0 ' + echo 'graph_vlabel Servers' + echo 'graph_scale no' + echo 'graph_category Ipvs' + echo 'graph_info Indicate the number of active servers 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 Active" + echo "a$NM.type GAUGE" + echo "a$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 + # If match the ip, print the line number + 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 + + # 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 + # ... except if the line contain TCP word (this start an other listen) + if ( echo $line | grep TCP > /dev/null ); then + break + fi + + 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 $COUNT + + # Remove temp file + rm -f $F1 +done diff --git a/plugins/ipvs/ipvs_bps b/plugins/ipvs/ipvs_bps new file mode 100755 index 00000000..0907bb4e --- /dev/null +++ b/plugins/ipvs/ipvs_bps @@ -0,0 +1,87 @@ +#!/bin/bash +# -*- bash -*- + +: << =cut + +=head1 NAME + +ipvs_conn -Indicate the number of bytes per second in ipvs + +=head1 CONFIGURATION + +[ipvs_*] +user root +env.ips IP1 IP2 + +=head1 AUTHOR + +Ricardo Fraile + +=head1 LICENSE + +GPLv2 + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + + +IPLIST=$ips + + +if [ "$1" = "autoconf" ]; then + echo yes + exit 0 +fi + +if [ "$1" = "config" ]; then + + echo 'graph_title Ipvs Traffic' + echo 'graph_args --base 1000 -l 0 ' + echo 'graph_vlabel Bytes in (-) / out (+)' + echo 'graph_category Ipvs' + echo 'graph_info Indicate the ipvs traffic.' + + for IP in $IPLIST; do + NM=`echo $IP | md5sum | cut -d - -f1 | sed 's/ //g' | cut -b 5-9` + + echo "down$NM.label Bytes $IP" + echo "down$NM.type GAUGE" + echo "down$NM.graph no" + echo "down$NM.cdef down$NM,8,*" + echo "down$NM.min 0" + + echo "up$NM.label Bytes $IP" + echo "up$NM.type GAUGE" + echo "up$NM.negative down$NM" + echo "up$NM.cdef up$NM,8,*" + echo "up$NM.info Bytes in $i" + echo "up$NM.min 0" + done + + exit 0 +fi + + + + +F1=`mktemp` +ipvsadm -l -n --rate| nl > $F1 + +for IP in $IPLIST; do + + COUNT1=`cat $F1 | grep TCP | grep $IP | awk '{print $7}'` + COUNT2=`cat $F1 | grep TCP | grep $IP | awk '{print $8}'` + NM=`echo $IP | md5sum | cut -d - -f1 | sed 's/ //g' | cut -b 5-9` + echo down$NM.value $COUNT1 + echo up$NM.value $COUNT2 + +done + +# Remove temp file +rm -f $F1 diff --git a/plugins/ipvs/ipvs_conn b/plugins/ipvs/ipvs_conn new file mode 100755 index 00000000..f458ee6a --- /dev/null +++ b/plugins/ipvs/ipvs_conn @@ -0,0 +1,122 @@ +#!/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 + +=head1 LICENSE + +GPLv2 + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + + +IPLIST=$ips + + +if [ "$1" = "autoconf" ]; then + echo yes + 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' + echo 'graph_category Ipvs' + 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 + # If match the ip, print the line number + 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 + + # 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 + # ... except if the line contain TCP word (this start an other listen) + if ( echo $line | grep TCP > /dev/null ); then + break + fi + + # 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)) + + 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 diff --git a/plugins/ipvs/ipvs_cps b/plugins/ipvs/ipvs_cps new file mode 100755 index 00000000..5a2274df --- /dev/null +++ b/plugins/ipvs/ipvs_cps @@ -0,0 +1,76 @@ +#!/bin/bash +# -*- bash -*- + +: << =cut + +=head1 NAME + +ipvs_conn -Indicate the number of conectios per second + +=head1 CONFIGURATION + +[ipvs_*] +user root +env.ips IP1 IP2 + +=head1 AUTHOR + +Ricardo Fraile + +=head1 LICENSE + +GPLv2 + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + + +IPLIST=$ips + + +if [ "$1" = "autoconf" ]; then + echo yes + exit 0 +fi + +if [ "$1" = "config" ]; then + + echo 'graph_title Ipvs connectios per second' + echo 'graph_args --base 1000 -l 0 ' + echo 'graph_vlabel Connections' + echo 'graph_scale no' + echo 'graph_category Ipvs' + echo 'graph_info Indicate the number of connections per second.' + + for IP in $IPLIST; do + NM=`echo $IP | md5sum | cut -d - -f1 | sed 's/ //g' | cut -b 5-9` + echo "a$NM.label $IP Connections" + echo "a$NM.type GAUGE" + echo "a$NM.min 0" + done + + exit 0 +fi + + + + +F1=`mktemp` +ipvsadm -l -n --rate| nl > $F1 + +for IP in $IPLIST; do + + COUNT=`cat $F1 | grep TCP | grep $IP | awk '{print $4}'` + NM=`echo $IP | md5sum | cut -d - -f1 | sed 's/ //g' | cut -b 5-9` + echo a$NM.value $COUNT + +done + +# Remove temp file +rm -f $F1