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 (143 lines) | stat: -rw-r--r-- 3,376 bytes parent folder | download | duplicates (4)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!@@GOODSH@@
# -*- sh -*-

set -e

: << =cut

=head1 NAME

netstat - Plugin to monitor network connections

=head1 CONFIGURATION

No configuration

=head1 AUTHOR

Unknown author

=head1 LICENSE

GPLv2

=head1 BUGS

=over 4

=item SuSE: passive connections rejected

At least one SuSE netstat appears to report "passive connections
rejected because of time stamp"

We have never seen that, patch requested.

=back

=head1 MAGIC MARKERS

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

=cut

. "$MUNIN_LIBDIR/plugins/plugin.sh"


NETSTAT_CMD=netstat


if [ "$1" = "autoconf" ]; then
	if ( "$NETSTAT_CMD" -s 2>/dev/null >/dev/null ); then
		echo yes
		exit 0
	else
		if [ $? -eq 127 ]
		then
			echo "no (program $NETSTAT_CMD not found)"
			exit 0
		else
			echo "no (unknown netstat return value $?)"
			exit 0
		fi
	fi
fi

if [ "$1" = "config" ]; then

	echo 'multigraph netstat'
	echo 'graph_title Netstat, combined'
	echo 'graph_args --units=si -l 1 --base 1000 --logarithmic'
	echo 'graph_vlabel TCP connections'
	echo 'graph_category network'
	echo 'graph_period second'
	echo 'graph_info This graph shows the TCP activity of all the network interfaces combined.'
	echo 'active.label active'
	echo 'active.type DERIVE'
	echo 'active.min 0'
	echo 'active.max 50000'
	echo 'active.info The number of active TCP openings per second.'
	print_warning active
	print_critical active
	echo 'passive.label passive'
	echo 'passive.type DERIVE'
	echo 'passive.min 0'
	echo 'passive.max 50000'
	echo 'passive.info The number of passive TCP openings per second.'
	print_warning passive
	print_critical passive
	echo 'failed.label failed'
	echo 'failed.type DERIVE'
	echo 'failed.min 0'
	echo 'failed.max 50000'
	echo 'failed.info The number of failed TCP connection attempts per second.'
	print_warning failed
	print_critical failed
	echo 'resets.label resets'
	echo 'resets.type DERIVE'
	echo 'resets.min 0'
	echo 'resets.max 50000'
	echo 'resets.info The number of TCP connection resets.'
	print_warning resets
	print_critical resets
	echo 'established.label established'
	echo 'established.type GAUGE'
	echo 'established.info The number of currently open connections.'
	print_warning established
	print_critical established

	echo ''

	echo 'multigraph netstat_established'
	echo 'graph_title Netstat, established only'
	echo 'graph_args --lower-limit 0'
	echo 'graph_vlabel TCP connections'
	echo 'graph_category network'
	echo 'graph_period second'
	echo 'graph_info This graph shows the TCP activity of all the network interfaces combined.'
	echo 'established.label established'
	echo 'established.type GAUGE'
	echo 'established.info The number of currently open connections.'
	print_warning established
	print_critical established

	exit 0
fi

# Newer versions of net tools' netstat have fixed the 'active connection
# openings' string from plural connections to singular. The match hereby is for
# both cases.
#
echo 'multigraph netstat'
"$NETSTAT_CMD" -s | awk '
/active connection(s)? ope/  { print "active.value " $1 }
/passive connection ope/  { print "passive.value " $1 }
/failed connection/       { print "failed.value " $1 }
/connection resets/       { print "resets.value " $1 }
/connections established/ { print "established.value " $1 }'

echo

echo 'multigraph netstat_established'
"$NETSTAT_CMD" -s | awk '
/connections established/ { print "established.value " $1 }'