2
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/network/multibandwidth

113 lines
3.1 KiB
Text
Raw Normal View History

#!/bin/sh
2017-03-23 11:15:32 +01:00
. "$MUNIN_LIBDIR/plugins/plugin.sh"
: <<=cut
=head1 NAME
multibandwidth - Plugin to monitor the bandwidth between localhost and serveral hosts.
=head1 APPLICABLE SYSTEMS
2017-03-22 15:53:53 +01:00
All systems with “bash”, and “munin”
=head1 REQUIREMENTS
bing installed.
You can install bing by using (Ubuntu/Debian): apt-get install bing
=head1 CONFIGURATION
The following is the default configuration
[multibandwidth]
user root
env.hosts example.org example2.org example3.org
env.samples 10
2017-03-23 11:15:32 +01:00
env.small_packet_size 44
env.big_packet_size 108
- env.hosts explanation: hostname or IP of the hosts to calculate the bandwidth.
- env.samples explanation: Reset stats after sending samples ECHO_REQUEST packets.
2017-03-22 15:53:53 +01:00
- env.small_packet_size explanation: Specifies the number of data bytes to be sent in the small
packets. The default and minimum value is 44.
2017-03-22 15:53:53 +01:00
- env.big_packet_size explanation: Specifies the number of data bytes to be sent in the big
packets. The default is 108. The size should be chosen so that big packet roundtrip times
are long enough to be accurately measured.
=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 Bertolas help <https://www.linkedin.com/in/bertolamarco/>
=head1 LICENSE
GPLv2
=cut
case $1 in
config)
echo graph_title MultiBandwidth
2017-03-23 11:15:32 +01:00
echo 'graph_vlabel bps'
2017-03-22 15:53:53 +01:00
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
2017-03-23 11:15:32 +01:00
fieldname="host_$(clean_fieldname "$host")"
echo "$fieldname.label $host"
echo "$fieldname.draw LINE2"
echo "$fieldname.info Bandwidth statistics for $host"
done
exit 0;;
autoconf)
if command -v bing >/dev/null 2>&1; then
echo 'yes'
exit 0;
else
echo 'no (bing not installed)'
exit 0;
fi
esac
#Calculating the bandwidth
for host in $hosts; do
2017-03-23 11:15:32 +01:00
fieldname="host_$(clean_fieldname "$host")"
printf "$fieldname.value ";
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 \
|grep "estimated link" -A 2 \
| grep bps \
| awk '{print $2}' \
| cut -d "b" -f1)
if (echo "$SPEED" | grep -q "M"); then
2017-03-23 11:15:32 +01:00
echo "$SPEED" | awk '{a+=$1} END{print a*1000000}'
2017-03-22 15:53:53 +01:00
elif (echo "$SPEED" | grep -q "K"); then
echo "$SPEED" | awk '{a+=$1} END{print a*1000}'
2017-03-23 11:15:32 +01:00
elif (echo "$SPEED" | grep -q "G"); then
echo "$SPEED" | awk '{a+=$1} END{print a*1000000000}'
2017-03-22 15:53:53 +01:00
else
2017-03-23 11:15:32 +01:00
echo "Error: no data (timeout)" >&2
2017-03-22 15:53:53 +01:00
fi
done