2017-04-04 15:48:24 +02:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
. "$MUNIN_LIBDIR/plugins/plugin.sh"
|
|
|
|
|
|
|
|
|
|
: <<=cut
|
|
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
|
|
multibandwidth - Plugin to monitor the bandwidth between localhost and serveral hosts.
|
|
|
|
|
|
|
|
|
|
=head1 APPLICABLE SYSTEMS
|
|
|
|
|
|
2018-07-11 20:38:38 +02:00
|
|
|
|
All systems with "bing" installed.
|
2017-04-04 15:48:24 +02:00
|
|
|
|
|
|
|
|
|
=head1 REQUIREMENTS
|
|
|
|
|
|
|
|
|
|
bing installed.
|
|
|
|
|
|
|
|
|
|
You can install bing by using (Ubuntu/Debian): apt-get install bing
|
|
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
2018-07-11 20:34:38 +02:00
|
|
|
|
The following example configuration shows all settings. Only "hosts" is required for
|
|
|
|
|
minimal configuration.
|
2017-04-04 15:48:24 +02:00
|
|
|
|
|
|
|
|
|
[multibandwidth]
|
|
|
|
|
user root
|
|
|
|
|
env.hosts example.org example2.org example3.org
|
|
|
|
|
env.samples 15
|
|
|
|
|
env.small_packet_size 44
|
|
|
|
|
env.big_packet_size 108
|
2018-07-11 20:29:31 +02:00
|
|
|
|
env.max_valid_bps 15728640
|
2017-04-04 15:48:24 +02:00
|
|
|
|
|
2018-07-11 20:34:38 +02:00
|
|
|
|
- env.hosts: space separated list of hostnames or IPs of the hosts to calculate the bandwidth.
|
|
|
|
|
This setting is required.
|
2017-04-04 15:48:24 +02:00
|
|
|
|
|
2018-07-11 20:34:38 +02:00
|
|
|
|
- env.samples: Reset stats after sending this number of ECHO_REQUEST packets.
|
|
|
|
|
Defaults to 15 samples.
|
2017-03-10 15:44:28 +01:00
|
|
|
|
|
2018-07-11 20:34:38 +02:00
|
|
|
|
- env.small_packet_size: Specifies the number of data bytes to be sent in the small
|
2017-03-22 15:53:53 +01:00
|
|
|
|
packets. The default and minimum value is 44.
|
2017-03-10 15:44:28 +01:00
|
|
|
|
|
2018-07-11 20:34:38 +02:00
|
|
|
|
- env.big_packet_size: Specifies the number of data bytes to be sent in the big
|
2017-03-22 15:53:53 +01:00
|
|
|
|
packets. The default is 108. The size should be chosen so that big packet roundtrip times
|
|
|
|
|
are long enough to be accurately measured.
|
2017-03-10 15:44:28 +01:00
|
|
|
|
|
2018-07-11 20:34:38 +02:00
|
|
|
|
- env.max_valid_bps: bing have some random spikes. This variable is used to indicate
|
2017-03-31 14:19:14 +02:00
|
|
|
|
the maximum value of mbps that can be recorded (in bps).
|
2018-07-11 20:34:38 +02:00
|
|
|
|
Defaults to the empty string (no validity check).
|
2017-03-10 15:44:28 +01:00
|
|
|
|
|
|
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
|
|
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
|
|
=head1 VERSION
|
|
|
|
|
|
|
|
|
|
1.1.17
|
|
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
|
|
Jose Manuel Febrer Cortés <https://www.linkedin.com/in/jfebrer/>
|
2017-03-22 15:53:53 +01:00
|
|
|
|
Marco Bertola’s help <https://www.linkedin.com/in/bertolamarco/>
|
2017-03-10 15:44:28 +01:00
|
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
|
|
GPLv2
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
|
2018-07-11 20:34:38 +02:00
|
|
|
|
hosts=${hosts:-}
|
|
|
|
|
samples=${samples:-15}
|
|
|
|
|
small_packet_size=${small_packet_size:-44}
|
|
|
|
|
big_packet_size=${big_packet_size:-108}
|
|
|
|
|
max_valid_bps=${max_valid_bps:-15728640}
|
|
|
|
|
|
2017-03-10 15:44:28 +01:00
|
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
|
config)
|
2018-07-11 20:36:49 +02:00
|
|
|
|
echo graph_title MultiBandwidth
|
|
|
|
|
echo 'graph_vlabel bps'
|
|
|
|
|
echo 'graph_args --base 1024 -l 0'
|
|
|
|
|
echo 'graph_scale yes'
|
|
|
|
|
echo 'graph_category network'
|
|
|
|
|
echo 'graph_info This graph shows the bandwidth between localhost and serveral hosts'
|
|
|
|
|
for host in $hosts; do
|
|
|
|
|
fieldname="host_$(clean_fieldname "$host")"
|
|
|
|
|
echo "$fieldname.label $host"
|
|
|
|
|
echo "$fieldname.draw LINE2"
|
|
|
|
|
echo "$fieldname.info Bandwidth statistics for $host"
|
|
|
|
|
done
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
2017-03-10 15:44:28 +01:00
|
|
|
|
autoconf)
|
2018-07-11 20:36:49 +02:00
|
|
|
|
if command -v bing 2>/dev/null; then
|
|
|
|
|
echo 'yes'
|
|
|
|
|
else
|
|
|
|
|
echo 'no (bing not installed)'
|
|
|
|
|
fi
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
2017-03-10 15:44:28 +01:00
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
2018-07-11 20:36:49 +02:00
|
|
|
|
# Calculating the bandwidth
|
2017-03-10 15:44:28 +01:00
|
|
|
|
for host in $hosts; do
|
2017-03-23 11:15:32 +01:00
|
|
|
|
fieldname="host_$(clean_fieldname "$host")"
|
2017-03-22 15:53:53 +01:00
|
|
|
|
|
|
|
|
|
SPEED=$(timeout 6 bing localhost "$host" -n -c 1 -e "$samples" -s "$small_packet_size" -S "$big_packet_size" 2>/dev/null \
|
2018-07-11 20:36:49 +02:00
|
|
|
|
| grep "estimated link" -A 2 \
|
2017-03-22 15:53:53 +01:00
|
|
|
|
| grep bps \
|
|
|
|
|
| awk '{print $2}' \
|
|
|
|
|
| cut -d "b" -f1)
|
|
|
|
|
|
2018-07-11 20:25:57 +02:00
|
|
|
|
if echo "$SPEED" | grep -q "M"; then
|
|
|
|
|
RATE=$(echo "$SPEED" | awk '{ print int($1 * 1024 * 1024); }')
|
|
|
|
|
elif echo "$SPEED" | grep -q "K"; then
|
|
|
|
|
RATE=$(echo "$SPEED" | awk '{ print int($1 * 1024); }')
|
|
|
|
|
elif echo "$SPEED" | grep -q "G"; then
|
|
|
|
|
RATE=$(echo "$SPEED" | awk '{ print int($1 * 1024 * 1024 * 1024); }')
|
2017-03-22 15:53:53 +01:00
|
|
|
|
else
|
2018-07-11 20:26:20 +02:00
|
|
|
|
RATE="U"
|
2017-03-23 11:15:32 +01:00
|
|
|
|
echo "Error: no data (timeout)" >&2
|
2017-03-22 15:53:53 +01:00
|
|
|
|
fi
|
2018-07-11 20:29:31 +02:00
|
|
|
|
if [ -n "$max_valid_bps" ] && [ "$RATE" -gt "$max_valid_bps" ]; then
|
|
|
|
|
# the value is outside of the allowed range; discard it
|
|
|
|
|
RATE="U"
|
2018-07-11 20:25:57 +02:00
|
|
|
|
fi
|
|
|
|
|
echo "${fieldname}.value $RATE"
|
2017-03-10 15:44:28 +01:00
|
|
|
|
done
|