File: netstat.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 (103 lines) | stat: -rw-r--r-- 2,371 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!@@PERL@@
# -*- perl -*-

=head1 NAME

netstat - Plugin to monitor network connections

=head1 CONFIGURATION

No configuration

=head1 NOTES

=head2 DESCRIPTION

This will measure the amount of network traffic coming into and
out of the server.  It will report back the number of connections
accepted, requested, established, and closed.  It uses
/usr/bin/netstat to gather its information.

=head2 RESTRICTIONS

None known.  /usr/bin/netstat should be executable by everyone by default.

=head1 AUTHOR

Unknown author

=head1 LICENSE

GPLv2

=head1 MAGIC MARKERS

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

=cut

use strict;
use Munin::Plugin;

if (defined $ARGV[0] and $ARGV[0] eq "autoconf") {
    if(-e "/usr/bin/netstat" && -X "/usr/bin/netstat") {
        print "yes\n";
    } else {
        print "no\n";
    }
    exit 0;
} elsif (defined $ARGV[0] and $ARGV[0] eq "config") {
    print "graph_title Netstat\n";
    print "graph_args --base 1000 --logarithmic\n";
    print "graph_vlabel active connections per \${graph_period}\n";
    print "graph_category network\n";
    print "active.label active\n";
    print "active.type DERIVE\n";
    print "active.min 0\n";
    print "active.max 50000\n";
    print_thresholds("active");
    print "passive.label passive\n";
    print "passive.type DERIVE\n";
    print "passive.min 0\n";
    print "passive.max 50000\n";
    print_thresholds("passive");
    print "failed.label failed\n";
    print "failed.type DERIVE\n";
    print "failed.min 0\n";
    print "failed.max 50000\n";
    print_thresholds("failed");
    print "resets.label resets\n";
    print "resets.type DERIVE\n";
    print "resets.min 0\n";
    print "resets.max 50000\n";
    print_thresholds("resets");
    print "established.label established\n";
    print "established.type GAUGE\n";
    print "established.max 50000\n";
    print_thresholds("established");
    exit 0;
}

my %trans = (
              tcpActiveOpens  => "active",
              tcpPassiveOpens => "passive",
              tcpAttemptFails => "failed",
              tcpEstabResets  => "resets",
              tcpCurrEstab    => "established"
            );

# Slurp mode
undef $/;

open(NETSTAT, '/usr/bin/netstat -s -P tcp|');
$_ = <NETSTAT>;
close(NETSTAT);

s/^\n*//;

s/^TCP/   /m;

while (/\s+(\w+)\s*=\s*(\d+)/g) {
  print "$trans{$1}.value $2\n" if exists $trans{$1};
}