File: fw_packets.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 (92 lines) | stat: -rw-r--r-- 1,754 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
#!@@PERL@@ -w
# -*- perl -*-

use strict;
use warnings;

=head1 NAME

fw_packets - Plugin to monitor the throughput of a firewall

=head1 CONFIGURATION

This plugin must run with root privileges

=head1 CONFIGURATION EXAMPLE

@@CONFDIR@@/plugin-conf.d/global or other file in that dir must contain:

 [fw*]
  user root

=head1 AUTHOR

Unknown author

=head1 LICENSE

GPLv2

=head1 MAGIC MARKERS

 #%# family=auto
 #%# capabilities=autoconf

=cut

if ( $ARGV[0] ) {

    if ( $ARGV[0] eq 'autoconf' ) {
	if ( -r '/proc/net/snmp') {
	    print "yes\n";
	    exit 0;
	}
	print "no (file /proc/net/snmp not readable)\n";
	exit 0;

    } elsif ( $ARGV[0] eq 'config' ) {
	print <<EOM;
graph_title Firewall Throughput
graph_args --base 1000 -l 0
graph_vlabel Packets/\${graph_period}
graph_category network
received.label Received
received.draw AREA
received.type DERIVE
received.min 0
forwarded.label Forwarded
forwarded.draw LINE2
forwarded.type DERIVE
forwarded.min 0
EOM
# Is LINE1 better I wonder?  The lines are meant to show how large a
# portion of the total received packets gets forwarded.
# rejected.label rejected
# rejected.draw LINE2
# rejected.type COUNTER
	exit 0;
    }
}

open(F, "/proc/net/snmp") or die "Cannot read /proc/net/snmp: $!\n";

while (<F>) {
    if (/^Ip: \d/) {
	my @ip = split;
	my $forwarded = $ip[6];  #forwarded
	my $received = $ip[3];   #received
	print "received.value $received\n";
	print "forwarded.value $forwarded\n";

	# This calculation is invalid, the packet may have been
	# destined for the firewall, then the difference is wrong.  If
	# you firewall does not receive traffic itself it is correct
	# though.
	#
	# print "rejected.value ", $received - $forwarded,"\n";
	last;
    }
}
close(F);

# vim:syntax=perl