]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/files/default/plugins/fw_forwarded_local
Update rubocop and fix new warnings
[chef.git] / cookbooks / munin / files / default / plugins / fw_forwarded_local
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 fw_forwarded_local - Plugin to monitor network connections.
6
7 =head1 CONFIGURATION
8
9 This plugin must run with root privileges
10
11 =head2 CONFIGURATION EXAMPLE
12
13 /etc/munin/plugin-conf.d/global or other file in that dir must contain:
14
15  [fw_*]
16   user root
17
18 =head1 NOTES
19
20 =over
21
22 =item * forward: number of connections forwarded
23
24 =item * local: number of connections for the host itself
25
26 =back
27
28 =head1 AUTHORS
29
30 2011.09.23: Perl version by Alex Tomlins
31
32 =head1 MAGIC MARKERS
33
34  #%# family=auto
35  #%# capabilities=autoconf
36
37 =cut
38
39 use strict;
40 use Munin::Plugin;
41
42 my $conntrack = '/usr/sbin/conntrack';
43 my $nf_conntrack_file = '/proc/net/nf_conntrack';
44 my $ip_conntrack_file = '/proc/net/ip_conntrack';
45
46 if ( defined($ARGV[0]) and $ARGV[0] eq "autoconf" ) {
47     if ( -x $conntrack or -r $nf_conntrack_file or -r $ip_conntrack_file) {
48         print "yes\n";
49     } else {
50         print "no\n";
51     }
52     exit 0;
53 }
54
55 if ( defined($ARGV[0]) and $ARGV[0] eq "config" ) {
56     print "graph_title ipconntrack\n";
57     print "graph_args -l 0 --base 1000\n";
58     print "graph_vlabel established connections\n";
59     print "graph_category network\n";
60     print "forward.label forward\n";
61     print "forward.type GAUGE\n";
62     print "local.label local\n";
63     print "local.type GAUGE\n";
64     exit 0;
65 }
66
67 my $command;
68 if ( -x $conntrack) {
69     $command = "$conntrack -L -o extended 2>/dev/null";
70 } elsif ( -r $nf_conntrack_file ) {
71     $command = "cat $nf_conntrack_file";
72 } elsif (-r $ip_conntrack_file ) {
73     $command = "cat $ip_conntrack_file";
74 } else {
75     die "Can't find conntrack information\n";
76 }
77
78 my $local = 0;
79 my $forward = 0;
80 open CMD, "$command|";
81 while (<CMD>) {
82     if (/ESTABLISHED\s+src=(\S+)\s+dst=(\S+)\s+sport.*src=(\S+)\s+dst=(\S+)/) {
83         if ($1 eq $4) {
84             $local++;
85         } else {
86             $forward++;
87         }
88     }
89 }
90 close CMD;
91
92 print "forward.value $forward\n";
93 print "local.value $local\n"