#!/bin/sh
#
# Wildcard-plugin to monitor network interfaces. To monitor an
# interface, link if_<interface> to this file. E.g.
#
#    ln -s /usr/share/node/node/plugins-auto/if_ /etc/munin/node.d/if_eth0
#
# ...will monitor eth0.
#
# Any devince found in /proc/net/dev can be monitored. Examples include
# ipsec*, eth*, irda* and lo. Please note that vlans and aliases cannot
# be monitored with this plugin.
#
# $Log: if_.in,v $
# Revision 1.1  2004/01/02 18:50:01  jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.3  2003/11/07 22:12:50  jimmyo
# Changed deprecated plugin options
#
# Revision 1.2  2003/11/07 17:43:16  jimmyo
# Cleanups and log entries
#
#
#
# Magic markers (optional - used by munin-config and some installation
# scripts):
#
#%# family=auto
#%# capabilities=autoconf suggest


INTERFACE=`basename $0 | sed 's/^if_//g'`

if [ "$1" = "autoconf" ]; then
	if [ -r /proc/net/dev ]; then
		echo yes
		exit 0
	else
		echo "no (/proc/net/dev not found)"
		exit 1
	fi
fi

if [ "$1" = "suggest" ]; then
	if [ -r /proc/net/dev ]; then
		grep eth /proc/net/dev | cut -f1 -d: | sed 's/ //g'
		exit 0
	else
		exit 1
	fi
fi

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

	echo "graph_order down up" 
	echo "graph_title $INTERFACE traffic"
	echo 'graph_args --base 1000'
	echo 'graph_vlabel bps in (-) / out (+)'
	echo 'down.label received'
        echo 'down.type COUNTER'
        echo 'down.graph no'
        echo 'down.cdef down,8,*'
        echo 'up.label bps'
	echo 'up.type COUNTER'
	echo 'up.negative down'
	echo 'up.cdef up,8,*'
	exit 0
fi;

grep $INTERFACE /proc/net/dev | cut -f2 -d: | awk "{ print \"up.value \" \$9 \"\ndown.value \" \$1}"

