File: netstat.in

package info (click to toggle)
munin 1.2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,940 kB
  • ctags: 98
  • sloc: sh: 4,215; makefile: 452; perl: 135
file content (88 lines) | stat: -rw-r--r-- 2,261 bytes parent folder | download
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
#!@@PERL@@
#
# $Id: netstat.in 860 2005-03-29 20:32:59Z ilmari $
#
# $Log$
# Revision 1.6  2004/12/10 18:51:44  jimmyo
# linux/apt* has been forced to LANG=C, to get predictable output.
#
# Revision 1.5  2004/12/10 10:47:50  jimmyo
# Change name from ${scale} to ${graph_period}, to be more consistent.
#
# Revision 1.4  2004/12/09 22:12:56  jimmyo
# Added "graph_period" option, to make "graph_sums" usable.
#
# Revision 1.3  2004/11/21 00:17:12  jimmyo
# Changed a lot of plugins so they use DERIVE instead of COUNTER.
#
# Revision 1.2  2004/05/20 19:02:38  jimmyo
# Set categories on a bunch of plugins
#
# Revision 1.1  2004/01/29 19:21:20  jimmyo
# Moved generic netstat to linux-dir, as it is too spesific. Added Solaris version of the plugin as well. (SF#882354)
#
#
# Parameters:
#
#   config
#   autoconf
#
#%# family=auto
#%# capabilities=autoconf

use strict;

if (exists $ARGV[0] and $ARGV[0] eq "autoconf") {
  print "yes\n";
  exit;
} elsif (exists $ARGV[0] and $ARGV[0] eq "config") {
  print "graph_title Netstat\n";
  print "graph_args -l 0 --base 1000\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 "passive.label passive\n";
  print "passive.type DERIVE\n";
  print "passive.min 0\n";
  print "passive.max 50000\n";
  print "failed.label failed\n";
  print "failed.type DERIVE\n";
  print "failed.min 0\n";
  print "failed.max 50000\n";
  print "resets.label resets\n";
  print "resets.type DERIVE\n";
  print "resets.min 0\n";
  print "resets.max 50000\n";
  print "established.label established\n";
  print "established.type GAUGE\n";
  print "established.max 50000\n";
  exit;
}

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};
}