summaryrefslogtreecommitdiff
path: root/sysutils/munin-common/files/patch-plugins_node.d.freebsd_if__packets__.in
blob: 23b4536a8b876ba9e7093668dc0588b9b8131b6c (plain) (blame)
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
--- plugins/node.d.freebsd/if_packets_.in.orig	2014-12-10 15:34:51 UTC
+++ plugins/node.d.freebsd/if_packets_.in
@@ -0,0 +1,110 @@
+#!@@GOODSH@@
+# -*- sh -*-
+#
+# Wildcard-plugin to monitor network interfaces. To monitor an
+# interface, link if_packets_<interface> to this file. E.g.
+#
+#    ln -s /usr/share/munin/node/plugins-auto/if_packets_ /etc/munin/node.d/if_packets_eth0
+#
+# ...will monitor eth0.
+#
+# To aggregate all network interfaces on the system (except lo0),
+# link if_packets_aggregated to this file.
+#
+# Any device found in /usr/bin/netstat can be monitored.
+#
+# Magic markers (optional - used by munin-config and some installation
+# scripts):
+#
+#%# family=auto
+#%# capabilities=autoconf suggest
+
+INTERFACE=${0##*if_packets_}
+
+if [ "$1" = "autoconf" ]; then
+	if [ -x /sbin/ifconfig -o -x /usr/bin/netstat ]; then
+		echo yes
+		exit 0
+	else
+		echo "no (/usr/bin/netstat not found)"
+		exit 0
+	fi
+fi
+
+if [ "$1" = "suggest" ]; then
+	if [ -x /sbin/ifconfig ]
+	then
+		ifconfig -l | sed -Ee 's/[[:<:]](pfsync|faith|pf(log|sync)|lo|plip|carp|enc|fwe)[^ ]*//g' | xargs -n 1 echo
+		exit 0
+	elif [ -x /usr/bin/netstat ]; then
+		netstat -i -b -n | sed -n -e '/^faith/d' -e '/^lo[0-9]/d' -e '/^pf(log|sync)/d' -e '/<Link#[0-9]*>/s/\** .*//p'
+		exit 0
+	else
+		exit 1
+	fi
+fi
+
+if [ "$1" = "config" ]; then
+
+	echo "graph_order rpackets opackets"
+	echo "graph_title $INTERFACE pps"
+	echo 'graph_args --base 1000'
+	echo 'graph_vlabel packets per ${graph_period} in (-) / out (+)'
+	echo 'graph_category network'
+	echo "graph_info This graph shows the packets counter of the $INTERFACE network interface. Please note that the traffic is shown in packets per second."
+	echo 'rpackets.label received'
+	echo 'rpackets.type COUNTER'
+	echo 'rpackets.graph no'
+
+	echo 'rpackets.min 0'
+	echo 'opackets.label pps'
+	echo 'opackets.type COUNTER'
+	echo 'opackets.negative rpackets'
+
+	echo 'opackets.min 0'
+	echo "opackets.info Packets sent (+) and received (-) on the $INTERFACE network interface."
+	exit 0
+fi
+
+if [ "$INTERFACE" = "aggregated" ]; then
+	/usr/bin/netstat -i -b -n | grep -v '^lo' | awk '
+BEGIN { rsum = 0; osum = 0; }
+/<Link#[0-9]*>/ {
+	if (NF == 10) { 
+		rsum += $4; osum += $7;
+	} else if (NF == 11) {
+		if ($4 ~ /:/) {
+			rsum += $5; osum += $8;
+		} else {
+			rsum += $4; osum += $8;
+		}
+	} else { # NF == 12
+		rsum += $6; osum += $9;
+	}
+}
+END {
+	printf "rpackets.value %i\n", rsum;
+	printf "opackets.value %i\n", osum;
+}'
+
+else
+	/usr/bin/netstat -i -b -n -I $INTERFACE | awk '
+/<Link#[0-9]*>/ {
+	if (NF == 10) {
+		print "rpackets.value", $4;
+		print "opackets.value", $7;
+	} else if (NF == 11) {
+		if ($4 ~ /:/) {
+			print "rpackets.value", $5;
+			print "opackets.value", $8;
+		} else {
+			print "rpackets.value", $4;
+			print "opackets.value", $8;
+		}
+	} else { # NF == 12
+		print "rpackets.value", $5;
+		print "opackets.value", $9;
+	}
+}'
+fi
+