scripts/munin/sockets
Antoine Durand-Gasselin 6e61a4a029 [munin/sockets] on factorise le code
darcs-hash:20090421211242-bd074-3e936372c575ab42848a053f78281a9044dc0dcd.gz
2009-04-21 23:12:42 +02:00

60 lines
1.2 KiB
Bash
Executable file

#!/bin/bash
#
# # Parameters:
#
# config (required)
# autoconf (optional - used by munin-config)
# suggest (optional - used by munin-config)
#
#. $MUNIN_LIBDIR/plugins/plugin.sh
myname="connexions"
name="${name-\<$myname\>}"
REGEX="${regex-\<$name\>}"
services=(http ssh smtp imap nfs ldap)
if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi
if [ "$1" = "suggest" ]; then
exit 0
fi
if [ "$1" = "config" ]; then
cat <<EOF
graph_title Number of $myname
graph_args --base 1000 --vertical-label connexions -l 0
graph_category network
`for dmn in ${services[@]}; do echo $dmn.label Connexions $dmn; done`
other.label Connexions diverses
in.label Connexions entrantes
out.label Connexions sortantes
EOF
exit 0
fi
ip=$(ifconfig | perl -ne 'print ${^MATCH} if /10\.231\.136\.\d+/p')
ips=${IP/10/}
TMP=`mktemp -t sockets.XXXXXX`
trap "rm $TMP* 2>/dev/null" 0
/sbin/ss > $TMP
for dmn in ${services[@]}; do
printf "$dmn.value "
grep "$ips:$dmn" $TMP | wc -l
done
printf "other.value "
perl -ne "print if ! /$ips:`echo ${services[@]} | sed 's/ /|/g'`/" $TMP | wc -l
printf "in.value "
perl -ne "print if ! /$ips:\d{5}/" $TMP | wc -l
printf "out.value "
perl -ne "print if /$ips:\d{5}/" $TMP | wc -l