Lines 43-49
monitored with this plugin.
Link Here
|
43 |
|
43 |
|
44 |
=head1 AUTHOR |
44 |
=head1 AUTHOR |
45 |
|
45 |
|
46 |
Unknown author |
46 |
Original author unknown |
|
|
47 |
|
48 |
Copyright (C) 2011 Diego Elio Petteno' <flameeyes@flameeyes.eu> |
47 |
|
49 |
|
48 |
=head1 LICENSE |
50 |
=head1 LICENSE |
49 |
|
51 |
|
Lines 64-149
Unknown license
Link Here
|
64 |
|
66 |
|
65 |
INTERFACE=${0##*if_} |
67 |
INTERFACE=${0##*if_} |
66 |
|
68 |
|
67 |
findspeed () { |
|
|
68 |
|
69 |
# Who whould have thought it's so much work to determine the |
69 |
# Who whould have thought it's so much work to determine the |
70 |
# maximum speed of a network interface. Buckle up! |
70 |
# maximum speed of a network interface. Buckle up! |
|
|
71 |
findspeed_mbps() { |
72 |
# sysfs can report the speed if the driver supports it |
73 |
if [ -r /sys/class/net/$INTERFACE/speed ]; then |
74 |
SPEED="$(cat /sys/class/net/$INTERFACE/speed 2>/dev/null)" |
75 |
if [ -n "$SPEED" ]; then |
76 |
echo $SPEED |
77 |
return |
78 |
fi |
79 |
fi |
71 |
|
80 |
|
72 |
IWLIST="$(type -p iwlist)" |
|
|
73 |
|
74 |
WIRELESS=0 |
75 |
# Do not use interface name to guess technology. Many many |
81 |
# Do not use interface name to guess technology. Many many |
76 |
# wifi drivers use "eth*" names. |
82 |
# wifi drivers use "eth*" names. |
77 |
case $IWLIST in |
83 |
IWLIST="$(type -p iwlist)" |
78 |
|
84 |
if [ -x "$IWLIST" ]; then |
79 |
'') |
85 |
SPEED=$($IWLIST $INTERFACE rate 2>&1 | |
80 |
# Used to use iwconfig to look for "no wireless |
86 |
awk 'BEGIN { RATE=U } |
81 |
# extentions" message - but this seemed un-needed. If we |
87 |
{ if ($2 == "Mb/s") RATE=$1; } |
82 |
# don't have iwlist we can't find out if # the interface |
88 |
END { print RATE; }') |
83 |
# is wireless |
89 |
|
84 |
:;; |
90 |
if [ "$SPEED" != "U" ]; then |
85 |
*) IWO="$($IWLIST $INTERFACE rate 2>&1)" |
91 |
echo $SPEED |
86 |
case $IWO in |
92 |
return |
87 |
*no*) :;; |
93 |
fi |
88 |
*) WIRELESS=1;; |
94 |
fi |
89 |
esac |
|
|
90 |
;; |
91 |
esac |
92 |
|
95 |
|
93 |
SPEED=U |
|
|
94 |
# Find speed in Mbps. - or not |
95 |
case $WIRELESS:$IWLIST in |
96 |
0:*) |
97 |
ETHTOOL="$(type -p ethtool)" |
96 |
ETHTOOL="$(type -p ethtool)" |
98 |
if [ -x "$ETHTOOL" ]; then |
97 |
if [ -x "$ETHTOOL" ]; then |
99 |
SPEED="$($ETHTOOL $INTERFACE 2>&1 | |
98 |
SPEED="$($ETHTOOL $INTERFACE 2>&1 | |
100 |
awk '/Speed:/ { gsub(/[^0-9]*/,"",$2); print $2; }')" |
99 |
awk '/Speed:/ { gsub(/[^0-9]*/,"",$2); print $2; }')" |
101 |
case $SPEED in |
|
|
102 |
[0-9]*) :;; # OK |
103 |
*) SPEED=U;; # Could be "unknown" |
104 |
esac |
105 |
else |
106 |
INSTALL="ethtool" |
107 |
fi |
108 |
;; |
109 |
1:/*) |
110 |
# Current bit rate is not very interesting, it varies too often |
111 |
SPEED=$(echo "$IWO" | |
112 |
awk 'BEGIN { RATE=U } |
113 |
{ if ($2 == "Mb/s") RATE=$1; } |
114 |
END { print RATE; }') |
115 |
|
100 |
|
116 |
;; |
101 |
if [ $SPEED = [0-9]* ]; then |
117 |
*) |
102 |
echo $SPEED |
118 |
# Wireless interface, cannot find iwlist |
103 |
return |
119 |
INSTALL="wireless-tools" |
104 |
fi |
120 |
;; |
105 |
fi |
121 |
esac |
|
|
122 |
|
106 |
|
123 |
MIITOOL="$(type -p mii-tool)" |
107 |
MIITOOL="$(type -p mii-tool)" |
124 |
case $SPEED:$MIITOOL in |
108 |
if [ -x $MIITOOL ]; then |
125 |
U:/*) |
109 |
case $($MIITOOL $INTERFACE 2>&1) in |
126 |
SPEED="$($MIITOOL $INTERFACE 2>&1)" |
110 |
*1000base*) echo 1000; return ;; |
127 |
case $SPEED in |
111 |
*100base*) echo 100; return ;; |
128 |
*1000base*) SPEED=1000;; # as if... |
112 |
*10base*) echo 10; return ;; |
129 |
*100base*) SPEED=100;; |
|
|
130 |
*10base*) SPEED=10;; |
131 |
*) SPEED=U;; |
132 |
esac |
113 |
esac |
133 |
;; |
|
|
134 |
esac |
135 |
|
136 |
# sysfs can report the speed if the driver supports it |
137 |
SYSFS="$(cat /sys/class/net/$INTERFACE/speed 2>/dev/null)" |
138 |
# If it can't, it fails on I/O, so we check cat's return value |
139 |
if [ $? -eq 0 -a "$SPEED" = "U" -a -n "$SYSFS" ]; then |
140 |
SPEED="$SYSFS" |
141 |
fi |
114 |
fi |
142 |
|
115 |
|
143 |
case $SPEED in |
116 |
echo U |
144 |
U) echo "up.info Traffic of the $INTERFACE interface. Unable to determine interface speed. Please install ethtool, wireless-tools (or mii-tool), whatever is appropriate for the interface." |
117 |
} |
145 |
return;; |
118 |
|
146 |
esac |
119 |
findspeed() { |
|
|
120 |
SPEED=$(findspeed_mbps) |
121 |
|
122 |
if [ -z $SPEED ]; then |
123 |
echo "up.info Traffic of the $INTERFACE interface. Unable to determine interface speed. Please install ethtool, wireless-tools, mii-tool or whatever is appropriate for the interface." |
124 |
return |
125 |
fi |
147 |
|
126 |
|
148 |
BPS=$(( $SPEED * 1000 * 1000 )) |
127 |
BPS=$(( $SPEED * 1000 * 1000 )) |
149 |
|
128 |
|
Lines 207-212
case $1 in
Link Here
|
207 |
esac |
186 |
esac |
208 |
|
187 |
|
209 |
# Escape dots in the interface name (eg. vlans) before using it as a regex |
188 |
# Escape dots in the interface name (eg. vlans) before using it as a regex |
|
|
189 |
if [ -r /sys/class/net/$INTERFACE/statistics/rx_bytes ]; then |
190 |
echo "down.value $(cat /sys/class/net/$INTERFACE/statistics/rx_bytes)" |
191 |
echo "up.value $(cat /sys/class/net/$INTERFACE/statistics/tx_bytes)" |
192 |
else |
210 |
awk -v interface="$INTERFACE" \ |
193 |
awk -v interface="$INTERFACE" \ |
211 |
'BEGIN { gsub(/\./, "\\.", interface) } \ |
194 |
'BEGIN { gsub(/\./, "\\.", interface) } \ |
212 |
$1 ~ "^" interface ":" { |
195 |
$1 ~ "^" interface ":" { |
Lines 214-217
awk -v interface="$INTERFACE" \
Link Here
|
214 |
print "down.value " $1 "\nup.value " $9 \ |
197 |
print "down.value " $1 "\nup.value " $9 \ |
215 |
}' \ |
198 |
}' \ |
216 |
/proc/net/dev |
199 |
/proc/net/dev |
217 |
|
200 |
fi |