Projet

Général

Profil

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

root / plugins / network / ip_forward_ @ 2c912170

Historique | Voir | Annoter | Télécharger (2 ko)

1
#!/bin/sh
2
#
3
# Wildcard-plugin to monitor forward traffic for network interfaces through iptables. To monitor an
4
# interface, link if_forward_<interface> to this file. E.g.
5
#
6
#    ln -s /usr/share/node/node/plugins-auto/if_forward_ /etc/munin/node.d/if_forward_eth0
7
#
8
# ...will monitor forwarded traffic through eth0.
9
#
10
# Additionally, you need these iptables rules as the first rules (they don't do anything, just make packet counts)
11
#
12
#    iptables -A FORWARD -i eth0
13
#    iptables -A FORWARD -o eth0
14
#
15
# Furthermore, this plugin needs to be run as root for iptables to work
16
#
17
# This plugin is based on the if_ and ip_ plugin.
18
#
19
# Magic markers (optional - used by munin-config and some installation
20
# scripts):
21
#
22
#%# family=auto
23
#%# capabilities=autoconf suggest
24

    
25

    
26
IF=`basename $0 | sed 's/^if_forward_//g'`
27

    
28
if [ "$1" = "autoconf" ]; then
29
	if [ -r /proc/net/dev ]; then
30
		iptables-save -c >/dev/null 2>/dev/null
31
		if [ $? -gt 0 ]; then
32
			echo "no (could not run iptables-save as user `whoami`)"
33
		else
34
			echo yes
35
		fi
36
	else
37
		echo "no (/proc/net/dev not found)"
38
	fi
39
	exit 0
40
fi
41

    
42
if [ "$1" = "suggest" ]; then
43
	if [ -r /proc/net/dev ]; then
44
		egrep '^ *(eth|wlan|ath|ra)[0-9]+:' /proc/net/dev | cut -f1 -d: | sed 's/ //g'
45
		exit 0
46
	else
47
		exit 1
48
	fi
49
fi
50

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

    
53
        echo "graph_order out in"
54
        echo "graph_title $IF forwarded traffic"
55
        echo 'graph_args --base 1000'
56
        echo 'graph_vlabel bits per ${graph_period}'
57
	echo 'graph_category network'
58
	echo "graph_info This graph shows only FORWARD traffic that pass through the interface."
59
        echo 'out.label sent'
60
        echo 'out.type DERIVE'
61
        echo 'out.min 0'
62
        echo 'out.cdef out,8,*'
63
        echo 'in.label received'
64
        echo 'in.type DERIVE'
65
        echo 'in.min 0'
66
        echo 'in.cdef in,8,*'
67
        exit 0
68
fi;
69

    
70
iptables-save -c | grep $IF | grep i | cut -f2 -d':' | cut -f1 -d']' | awk "{ print \"in.value \" \$0 }"
71
iptables-save -c | grep $IF | grep o | cut -f2 -d':' | cut -f1 -d']' | awk "{ print \"out.value \" \$0 }"
72