Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / network / ipt_basic_ @ 17f78427

Historique | Voir | Annoter | Télécharger (3,13 ko)

1 8dbd78cb Peter \'grin\' Gervai
#!/bin/sh
2
#$Id: ipt-basic_ 96 2005-10-12 16:54:19Z grin $
3
#
4
# (C)Copyright Peter grin at grin dot hu Gervai, 2005
5
# Released undel GPL v2.
6
#
7
# Plugin to monitor traffic through iptables.
8
# This plugin was designed to monitor FORWARDING interfaces
9
# on a router with only one-to-one forwarding (traffic goes into
10
# one interface goes out to the other).
11
#
12
# You can initialise the required iptables by running it manually:
13
#
14
#   ipt-basic_ initialise
15
#
16
# You should create two symlinks to this module:
17
#   ln -s ipt-basic_ ipt-basic_bytes
18
#   ln -s ipt-basic_ ipt-basic_pkts
19
#
20
# This plugin is based on the ip_ plugin.
21
#
22
# Revisions:
23
#  2006.01.00 - First release.
24
#  2006.11.26 - Use -j RETURN in rules, and sort interfaces
25 17f78427 Lars Kruse
#
26 8dbd78cb Peter \'grin\' Gervai
#
27
# Magic markers (optional - used by munin-config and some installation
28
# scripts):
29
#
30
#%# family=auto
31
#%# capabilities=autoconf
32
33
# ipt_bytes, ipt_pkts
34
TYPE=`basename $0 | sed 's/^ipt-basic_//g'`
35
36
if [ "$TYPE" != "bytes" -a "$TYPE" != "pkts" ]; then
37
	# if dear user forgot to use symlinks, default to ipt_bytes
38
	TYPE='bytes'
39
fi
40
41
# name of our iptable
42
TNAME='munin_node'
43
iptables='/sbin/iptables'
44
45
46
if [ "$1" = "autoconf" ]; then
47
	if [ -r /proc/net/dev ]; then
48 c9157be3 Lars Kruse
		RES=`$iptables -L $TNAME -nvx -w 2>&1 >/dev/null`
49 8dbd78cb Peter \'grin\' Gervai
		if [ $? -gt 0 ]; then
50
			echo "no (could not run iptables as user `whoami`; $RES)"
51
			exit 1
52
		else
53
			echo yes
54
			exit 0
55
		fi
56
	else
57
		echo "no (/proc/net/dev not found)"
58
		exit 1
59
	fi
60
fi
61
62
if [ "$1" = "suggest" ]; then
63
        echo "no parameters required!"
64
	exit 1
65
fi
66
67
68
if [ "$1" = "initialise" ]; then
69
	# creates the required tables
70
        $iptables -N $TNAME
71
        $iptables -F $TNAME
72
        # add to forward table (and delete dupe if exists
73
        $iptables -D FORWARD -j $TNAME 2> /dev/null
74
        $iptables -A FORWARD -j $TNAME
75
        DEVS=`cat /proc/net/dev|egrep "(eth|ppp)" | cut -d: -f1 | sort`
76
        for dev in $DEVS; do
77
        	$iptables -A $TNAME -j RETURN -i $dev
78
        done
79
	exit 1
80
fi
81
82 c9157be3 Lars Kruse
IFACES=`$iptables -L munin_node -nvx -w | awk '$6 ~ /(eth|ppp)[0-9]/ { if (done[$6]!=1) {print $6; done[$6]=1;}}'`
83 8dbd78cb Peter \'grin\' Gervai
84
if [ "$1" = "config" ]; then
85
86
        # echo "graph_order out in"
87 047358a0 Stig Sandbeck Mathisen
        if [ "$TYPE" = "pkts" ]; then
88 8dbd78cb Peter \'grin\' Gervai
        	echo "graph_title pkts"
89
	        echo 'graph_vlabel pkts per ${graph_period}'
90
        else
91
	        echo "graph_title traffic"
92
	        echo 'graph_vlabel bits per ${graph_period}'
93
        fi
94
        echo 'graph_args --base 1000'
95
	echo 'graph_category network'
96
        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.'
97 17f78427 Lars Kruse
98 8dbd78cb Peter \'grin\' Gervai
        for iface in $IFACES; do
99
        	echo "$iface.label ${iface}_received"
100
                echo "$iface.type DERIVE"
101
                echo "$iface.min 0"
102
	        if [ "$TYPE" != "pkts" ]; then
103
        	        # traf in BITS/sec
104
                	echo "$iface.cdef $iface,8,*"
105
                fi
106
        done
107
        exit 0
108
fi;
109
110 047358a0 Stig Sandbeck Mathisen
if [ "$TYPE" = "pkts" ]; then
111 c9157be3 Lars Kruse
	$iptables -L munin_node -nvx -w | egrep "eth|ppp" | awk "{ print \$6 \".value \" \$1 }"
112 8dbd78cb Peter \'grin\' Gervai
else
113 c9157be3 Lars Kruse
	$iptables -L munin_node -nvx -w | egrep "eth|ppp" | awk "{ print \$6 \".value \" \$2 }"
114 8dbd78cb Peter \'grin\' Gervai
fi