2009-01-27 14:23:07 +01:00
#!/bin/sh
#$Id: ipt-basic_ 96 2005-10-12 16:54:19Z grin $
#
# (C)Copyright Peter grin at grin dot hu Gervai, 2005
# Released undel GPL v2.
#
# Plugin to monitor traffic through iptables.
# This plugin was designed to monitor FORWARDING interfaces
# on a router with only one-to-one forwarding (traffic goes into
# one interface goes out to the other).
#
# You can initialise the required iptables by running it manually:
#
# ipt-basic_ initialise
#
# You should create two symlinks to this module:
# ln -s ipt-basic_ ipt-basic_bytes
# ln -s ipt-basic_ ipt-basic_pkts
#
# This plugin is based on the ip_ plugin.
#
# Revisions:
# 2006.01.00 - First release.
# 2006.11.26 - Use -j RETURN in rules, and sort interfaces
2018-08-02 02:03:42 +02:00
#
2009-01-27 14:23:07 +01:00
#
# Magic markers (optional - used by munin-config and some installation
# scripts):
#
#%# family=auto
#%# capabilities=autoconf
# ipt_bytes, ipt_pkts
TYPE=`basename $0 | sed 's/^ipt-basic_//g'`
if [ "$TYPE" != "bytes" -a "$TYPE" != "pkts" ]; then
# if dear user forgot to use symlinks, default to ipt_bytes
TYPE='bytes'
fi
# name of our iptable
TNAME='munin_node'
iptables='/sbin/iptables'
if [ "$1" = "autoconf" ]; then
if [ -r /proc/net/dev ]; then
2018-02-24 22:58:04 +01:00
RES=`$iptables -L $TNAME -nvx -w 2>&1 >/dev/null`
2009-01-27 14:23:07 +01:00
if [ $? -gt 0 ]; then
echo "no (could not run iptables as user `whoami`; $RES)"
else
echo yes
fi
else
echo "no (/proc/net/dev not found)"
fi
2018-09-16 04:01:57 +02:00
exit 0
2009-01-27 14:23:07 +01:00
fi
if [ "$1" = "suggest" ]; then
echo "no parameters required!"
exit 1
fi
if [ "$1" = "initialise" ]; then
# creates the required tables
$iptables -N $TNAME
$iptables -F $TNAME
# add to forward table (and delete dupe if exists
$iptables -D FORWARD -j $TNAME 2> /dev/null
$iptables -A FORWARD -j $TNAME
DEVS=`cat /proc/net/dev|egrep "(eth|ppp)" | cut -d: -f1 | sort`
for dev in $DEVS; do
$iptables -A $TNAME -j RETURN -i $dev
done
exit 1
fi
2018-02-24 22:58:04 +01:00
IFACES=`$iptables -L munin_node -nvx -w | awk '$6 ~ /(eth|ppp)[0-9]/ { if (done[$6]!=1) {print $6; done[$6]=1;}}'`
2009-01-27 14:23:07 +01:00
if [ "$1" = "config" ]; then
# echo "graph_order out in"
2014-10-04 20:02:19 +02:00
if [ "$TYPE" = "pkts" ]; then
2009-01-27 14:23:07 +01:00
echo "graph_title pkts"
echo 'graph_vlabel pkts per ${graph_period}'
else
echo "graph_title traffic"
echo 'graph_vlabel bits per ${graph_period}'
fi
echo 'graph_args --base 1000'
echo 'graph_category network'
echo 'graph_info This graph shows the traffic of the interfaces in bits per second, and should be precise above 50Mbps as well. All forwarded traffic is measured in the incoming counter of the given interface.'
2018-08-02 02:03:42 +02:00
2009-01-27 14:23:07 +01:00
for iface in $IFACES; do
echo "$iface.label ${iface}_received"
echo "$iface.type DERIVE"
echo "$iface.min 0"
if [ "$TYPE" != "pkts" ]; then
# traf in BITS/sec
echo "$iface.cdef $iface,8,*"
fi
done
exit 0
fi;
2014-10-04 20:02:19 +02:00
if [ "$TYPE" = "pkts" ]; then
2018-02-24 22:58:04 +01:00
$iptables -L munin_node -nvx -w | egrep "eth|ppp" | awk "{ print \$6 \".value \" \$1 }"
2009-01-27 14:23:07 +01:00
else
2018-02-24 22:58:04 +01:00
$iptables -L munin_node -nvx -w | egrep "eth|ppp" | awk "{ print \$6 \".value \" \$2 }"
2009-01-27 14:23:07 +01:00
fi