forked from munin-monitoring/munin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnmp__netstat
executable file
·116 lines (80 loc) · 3.88 KB
/
snmp__netstat
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
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/perl -w
=head1 NAME
snmp__netstat - Munin plugin to monitor the number of TCP network
connections on an SNMP device.
=head1 APPLICABLE SYSTEMS
Any SNMP-capable device that reports the TCP-MIB::tcpConnState
column of tcpConnTable.
=head1 CONFIGURATION
As a rule SNMP plugins need site specific configuration. The default
configuration (shown here) will only work on insecure sites/devices.
[snmp_*]
env.version 2
env.community public
In general SNMP is not very secure at all unless you use SNMP version
3 which supports authentication and privacy (encryption). But in any
case the community string for your devices should not be "public".
Please see 'perldoc Munin::Plugin::SNMP' for further configuration
information.
=head1 INTERPRETATION
The total number of TCP connections in each state. See RFC 793 or the
detailed information on the graph page for the meaning of each state.
=head1 MIB INFORMATION
This plugin requires support for the TCP-MIB (RFC 4022). It reports
the contents of the tcpConnState column of tcpConnTable.
=head1 MAGIC MARKERS
#%# family=snmpauto
#%# capabilities=snmpconf
=head1 BUGS
None known.
=head1 AUTHOR
Copyright (C) 2006 Lars Strand
Tidied and documented by Matthew Boyle in 2010.
=head1 LICENSE
GPLv2.
=cut
use strict;
use Munin::Plugin::SNMP;
my $oid = '1.3.6.1.2.1.6.13.1.1';
my @tcpStates = (
[ 0, 'closed', 'Connections waiting for a termination request acknowledgment from the remote TCP.' ],
[ 0, 'listen', 'Connections waiting for a request from any remote TCP and port.' ],
[ 0, 'synSent', 'Connections waiting for a matching request after having sent a connection request.' ],
[ 0, 'synReceived', 'Connections waiting for a confirming request acknowledgment after having both received and sent a connection request.' ],
[ 0, 'established', 'Connections opened and data received can be delivered to the user. The normal state for the data transfer phase of the connection.' ],
[ 0, 'finWait1', 'Connections waiting for a termination request from the remote TCP, or an acknowledgment of the connection termination request previously sent.' ],
[ 0, 'finWait2', 'Connections waiting for a termination request from the remote TCP.' ],
[ 0, 'closeWait', 'Connections waiting for a termination request from the local user.' ],
[ 0, 'lastAck', 'Connections waiting for an acknowledgment of the termination request previously sent to the remote TCP (which includes an acknowledgment of its connection termination request).' ],
[ 0, 'closing', 'Connections waiting for a termination request acknowledgment from the remote TCP.' ],
[ 0, 'timeWait', 'Connections waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its termination request.' ],
[ 0, 'deleteTCP', 'Connections terminated by a SNMP Management Station (put)' ]
);
if (defined $ARGV[0] and $ARGV[0] eq 'snmpconf') {
print "require ${oid}. [0-9]\n";
exit 0;
}
if (defined $ARGV[0] and $ARGV[0] eq 'config') {
my ($host) = Munin::Plugin::SNMP->config_session();
print "host_name $host\n" unless $host eq 'localhost';
print "graph_title Netstat\n";
print "graph_args --base 1000 --logarithmic\n";
print "graph_period seconds\n";
print "graph_category network\n";
print "graph_vlabel active connection\n";
print "graph_info This graph shows the TCP activity of all the network interfaces combined.\n";
foreach my $state (@tcpStates) {
print "$state->[1].label $state->[1]\n";
print "$state->[1].info $state->[2]\n";
}
exit 0;
}
my ($session, $error) = Munin::Plugin::SNMP->session();
my $connections = $session->get_entries(-columns => [ $oid ]);
# sum up the rows
foreach my $state (values %$connections) {
$tcpStates[$state-1]->[0]++; # states are counted from 1, not 0
}
foreach my $state (@tcpStates) {
print "$state->[1].value $state->[0]\n";
}