File: ip_.in

package info (click to toggle)
munin 1.2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,940 kB
  • ctags: 98
  • sloc: sh: 4,215; makefile: 452; perl: 135
file content (92 lines) | stat: -rw-r--r-- 2,551 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
#
# Wildcard-plugin to monitor IP addresses through iptables. To monitor an
# IP, link ip_<ipaddress> to this file. E.g.
#
#    ln -s /usr/share/node/node/plugins-auto/ip_ /etc/munin/node.d/ip_192.168.0.1
#
# ...will monitor the IP 192.168.0.1.
#
# Aditionally, you need these iptables rules as the first rules (they don't do anything, just make packet counts)
#
#    iptables -A INPUT -d 192.168.0.1
#    iptables -A OUTPUT -s 192.168.0.1
#
# Furthermore, this plugin needs to be run as root for iptables to work
#
# This plugin is based on the if_ plugin.
#
#$Log$
#Revision 1.7  2004/12/10 10:47:49  jimmyo
#Change name from ${scale} to ${graph_period}, to be more consistent.
#
#Revision 1.6  2004/12/09 22:12:56  jimmyo
#Added "graph_period" option, to make "graph_sums" usable.
#
#Revision 1.5  2004/11/21 00:17:12  jimmyo
#Changed a lot of plugins so they use DERIVE instead of COUNTER.
#
#Revision 1.4  2004/09/10 23:06:30  jimmyo
#Added accidentally deleted exit.
#
#Revision 1.3  2004/09/10 23:02:22  jimmyo
#Plugin linux/ip_ now does more proper autoconfig/suggest.
#
#Revision 1.2  2004/05/20 13:57:12  jimmyo
#Set categories to some of the plugins.
#
#Revision 1.1  2004/05/16 16:28:40  jimmyo
#Linux/ip_ wildcard plugin contributed by Mathy Vanvoorden (SF#954851).
#
#
# Magic markers (optional - used by munin-config and some installation
# scripts):
#
#%# family=auto
#%# capabilities=autoconf suggest


IP=`basename $0 | sed 's/^ip_//g'`

if [ "$1" = "autoconf" ]; then
	if [ -r /proc/net/dev ]; then
		iptables -L INPUT -v -n -x >/dev/null 2>/dev/null
		if [ $? -gt 0 ]; then
			echo "no (could not run iptables as user `whoami`)"
			exit 1
		else
			echo yes
			exit 0
		fi
	else
		echo "no (/proc/net/dev not found)"
		exit 1
	fi
fi

if [ "$1" = "suggest" ]; then
	iptables -L INPUT -v -n -x 2>/dev/null | awk '$8 ~ /[0-9]/ { if (done[$8]!=1) {print $8; done[$8]=1;}}'
	exit 0
fi

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

        echo "graph_order out in"
        echo "graph_title $IP traffic"
        echo 'graph_args --base 1000'
        echo 'graph_vlabel bits per ${graph_period}'
	echo 'graph_category network'
        echo 'out.label sent'
        echo 'out.type DERIVE'
        echo 'out.min 0'
        echo 'out.cdef out,8,*'
        echo 'in.label received'
        echo 'in.type DERIVE'
        echo 'in.min 0'
        echo 'in.cdef in,8,*' 
        exit 0
fi;

iptables -L INPUT -v -n -x | grep -m1 $IP | awk "{ print \"in.value \" \$2 }"
iptables -L OUTPUT -v -n -x | grep -m1 $IP | awk "{ print \"out.value \" \$2 }"