]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | # -*- sh -*- | |
3 | ||
4 | set -e | |
5 | ||
6 | : << =cut | |
7 | ||
8 | =head1 NAME | |
9 | ||
10 | if_err_ - Wildcard plugin to monitor errors, packet drops, and | |
11 | collisions of network interfaces | |
12 | ||
13 | =head1 CONFIGURATION | |
14 | ||
15 | This is a wildcard plugin. To monitor an interface, link | |
16 | if_err_<interface> to this file. E.g. | |
17 | ||
18 | ln -s /usr/share/munin/plugins/if_err_ \ | |
19 | /etc/munin/plugins/if_err_eth0 | |
20 | ||
21 | ...will monitor eth0. | |
22 | ||
23 | This plugin does not use environment variables. | |
24 | ||
25 | =head1 USAGE | |
26 | ||
27 | Any device found in /proc/net/dev can be monitored. Examples include | |
28 | ipsec*, eth*, irda* and lo. | |
29 | ||
30 | Please note that aliases cannot be monitored with this plugin. | |
31 | ||
32 | =head1 AUTHOR | |
33 | ||
34 | Unknown author | |
35 | ||
36 | =head1 LICENSE | |
37 | ||
38 | GPLv2 | |
39 | ||
40 | =head1 MAGIC MARKERS | |
41 | ||
42 | #%# family=auto | |
43 | #%# capabilities=autoconf suggest | |
44 | ||
45 | =cut | |
46 | ||
47 | . "$MUNIN_LIBDIR/plugins/plugin.sh" | |
48 | ||
49 | INTERFACE=${0##*/if_err_} | |
50 | ||
51 | if [ "$1" = "autoconf" ]; then | |
52 | if [ -r /proc/net/dev ]; then | |
53 | echo yes | |
54 | exit 0 | |
55 | else | |
56 | echo "no (/proc/net/dev not found)" | |
57 | exit 0 | |
58 | fi | |
59 | fi | |
60 | ||
61 | if [ "$1" = "suggest" ]; then | |
62 | if [ -r /proc/net/dev ]; then | |
63 | sed -rne '/^[[:space:]]*(lo|gre[[:digit:]]|sit[[:digit:]]+|[a-z0-9]+\.[0-9]+):/d;s,^[[:space:]]*([^:]+):.*,\1,p' /proc/net/dev | |
64 | fi | |
65 | exit 0 | |
66 | fi | |
67 | ||
68 | if [ "$1" = "config" ]; then | |
69 | address="$(ip -j address show dev $INTERFACE | jq -r '.[0].addr_info[].local' | tr '\n' ' ')" | |
70 | echo "graph_order rcvd trans" | |
71 | echo "graph_title $INTERFACE (${address% }) errors" | |
72 | echo 'graph_args --base 1000' | |
73 | # shellcheck disable=SC2016 | |
74 | echo 'graph_vlabel packets in (-) / out (+) per ${graph_period}' | |
75 | echo 'graph_category network' | |
76 | echo "graph_info This graph shows the amount of errors, packet drops, and collisions on the $INTERFACE network interface." | |
77 | echo 'rcvd.label errors' | |
78 | echo 'rcvd.type COUNTER' | |
79 | echo 'rcvd.graph no' | |
80 | echo 'rcvd.warning 1' | |
81 | echo 'trans.label errors' | |
82 | echo 'trans.type COUNTER' | |
83 | echo 'trans.negative rcvd' | |
84 | echo 'trans.warning 1' | |
85 | echo 'rxdrop.label drops' | |
86 | echo 'rxdrop.type COUNTER' | |
87 | echo 'rxdrop.graph no' | |
88 | echo 'txdrop.label drops' | |
89 | echo 'txdrop.type COUNTER' | |
90 | echo 'txdrop.negative rxdrop' | |
91 | echo 'collisions.label collisions' | |
92 | echo 'collisions.type COUNTER' | |
93 | print_warning rcvd | |
94 | print_critical rcvd | |
95 | print_warning trans | |
96 | print_critical trans | |
97 | exit 0 | |
98 | fi | |
99 | ||
100 | # Escape dots in the interface name (eg. vlans) before using it as a regex | |
101 | if [ -r "/sys/class/net/$INTERFACE/statistics/rx_bytes" ]; then | |
102 | echo "rcvd.value $(cat "/sys/class/net/$INTERFACE/statistics/rx_errors")" | |
103 | echo "trans.value $(cat "/sys/class/net/$INTERFACE/statistics/tx_errors")" | |
104 | echo "rxdrop.value $(cat "/sys/class/net/$INTERFACE/statistics/rx_dropped")" | |
105 | echo "txdrop.value $(cat "/sys/class/net/$INTERFACE/statistics/tx_dropped")" | |
106 | echo "collisions.value $(cat "/sys/class/net/$INTERFACE/statistics/collisions")" | |
107 | else | |
108 | awk -v interface="$INTERFACE" \ | |
109 | 'BEGIN { gsub(/\./, "\\.", interface) } | |
110 | $1 ~ "^" interface ":" { | |
111 | split($0, a, /: */); $0 = a[2]; | |
112 | print "rcvd.value " $3 "\ntrans.value " $11; | |
113 | print "rxdrop.value " $4 "\ntxdrop.value " $12; | |
114 | print "collisions.value " $14; | |
115 | }' \ | |
116 | /proc/net/dev | |
117 | fi |