File: vlan_linkuse_.in

package info (click to toggle)
munin 2.0.76-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,064 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (88 lines) | stat: -rw-r--r-- 2,250 bytes parent folder | download | duplicates (5)
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
#!@@PERL@@ -w
# Wildcard-script to monitor network interfaces. To monitor an
# interface, link vlan_<interface> to this file. E.g.
#
#    ln .vlan_inetuse_ vlan_inetuse_eth1-200
#
# ...will monitor eth1.200 <=> eth0
#
# The interface must also have an accounting iptables rule defined, _before_
# any action rules. E.g., in /etc/network/vlan-firewall.d/eth1-200-out, you
# will find:
#
# 	--out-interface eth0
#
# ...which will make the out-traffic graphable. (Both in and out-files must
# have such rules. Look at the existing for examples.
#
#%# family=manual


use strict;

my $INTERFACE=`basename $0 | sed 's/^vlan_linkuse_//g' | tr '_' '-'` ;
#my $INTERFACE="eth1-200";
chomp $INTERFACE;

my %contraries = ("dpt" => "spt", "spt" => "dpt");

my %in_octets = ();
my %out_octets = ();

open (IN, "/sbin/iptables -v -x -w -L $INTERFACE-in |") or
	die "Could not run iptables: $!\n";
while (<IN>)
{
	if (/^\s*\d+\s+(\d+)  +([a-z]+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+(?:\s+|)(.+|)$/)
	{
		my ($octets, $proto, $comment) = ($1, $2, $3);
		chop $comment;
		next unless (($proto eq "all") and (!$comment));
		if ($ARGV[0] and $ARGV[0] eq "config")
		{
			print "graph_order in out\n";
			print "graph_title VLAN $INTERFACE internet usage\n";
			print "graph_args --base 1000\n";
			print "graph_category network\n";
			print "graph_vlabel bits per \${graph_period} in (-) / out (+)\n";
			print "in.label bps\n";
			print "in.cdef in,8,*\n";
			print "in.graph no\n";
			print "in.type DERIVE\n";
			print "in.min 0\n";
		}
		else
		{
			print "in.value $octets\n";
		}
	}
}
close IN;
die "Error running iptables. Dying\n" if $?;

open (IN, "/sbin/iptables -v -x -w -L $INTERFACE-out |") or
	die "Could not run iptables: $!\n";
while (<IN>)
{
	if (/^\s*\d+\s+(\d+)  +([a-z]+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+(?:\s+|)(.+|)$/)
	{
		my ($octets, $proto, $comment) = ($1, $2, $3);
		chop $comment;
		next unless (($proto eq "all") and (!$comment));
		if ($ARGV[0] and $ARGV[0] eq "config")
		{
			print "out.label bps\n";
			print "out.cdef out,8,*\n";
			print "out.negative in\n";
			print "out.type DERIVE\n";
			print "out.min 0\n";
		}
		else
		{
			print "out.value $octets\n";
		}
	}
}
close IN;
die "Error running iptables. Dying\n" if $?;
# vim:syntax=perl