root / plugins / network / multibandwidth @ 1bed50bb
Historique | Voir | Annoter | Télécharger (3,07 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
|
| 3 |
. "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 4 |
|
| 5 |
: <<=cut |
| 6 |
|
| 7 |
=head1 NAME |
| 8 |
|
| 9 |
multibandwidth - Plugin to monitor the bandwidth between localhost and serveral hosts. |
| 10 |
|
| 11 |
=head1 APPLICABLE SYSTEMS |
| 12 |
|
| 13 |
All systems with “bash”, and “munin” |
| 14 |
|
| 15 |
=head1 REQUIREMENTS |
| 16 |
|
| 17 |
bing installed. |
| 18 |
|
| 19 |
You can install bing by using (Ubuntu/Debian): apt-get install bing |
| 20 |
|
| 21 |
=head1 CONFIGURATION |
| 22 |
|
| 23 |
The following is the default configuration |
| 24 |
|
| 25 |
[multibandwidth] |
| 26 |
user root |
| 27 |
env.hosts example.org example2.org example3.org |
| 28 |
env.samples 10 |
| 29 |
env.small_packet_size 44 |
| 30 |
env.big_packet_size 108 |
| 31 |
|
| 32 |
- env.hosts explanation: hostname or IP of the hosts to calculate the bandwidth. |
| 33 |
|
| 34 |
- env.samples explanation: Reset stats after sending samples ECHO_REQUEST packets. |
| 35 |
|
| 36 |
- env.small_packet_size explanation: Specifies the number of data bytes to be sent in the small |
| 37 |
packets. The default and minimum value is 44. |
| 38 |
|
| 39 |
- env.big_packet_size explanation: Specifies the number of data bytes to be sent in the big |
| 40 |
packets. The default is 108. The size should be chosen so that big packet roundtrip times |
| 41 |
are long enough to be accurately measured. |
| 42 |
|
| 43 |
|
| 44 |
=head1 MAGIC MARKERS |
| 45 |
|
| 46 |
#%# capabilities=autoconf |
| 47 |
|
| 48 |
=head1 VERSION |
| 49 |
|
| 50 |
1.1.17 |
| 51 |
|
| 52 |
=head1 AUTHOR |
| 53 |
|
| 54 |
Jose Manuel Febrer Cortés <https://www.linkedin.com/in/jfebrer/> |
| 55 |
Marco Bertola’s help <https://www.linkedin.com/in/bertolamarco/> |
| 56 |
|
| 57 |
=head1 LICENSE |
| 58 |
|
| 59 |
GPLv2 |
| 60 |
|
| 61 |
=cut |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
case $1 in |
| 66 |
config) |
| 67 |
echo graph_title MultiBandwidth |
| 68 |
echo 'graph_vlabel bps' |
| 69 |
echo 'graph_args --base 1024 -l 0' |
| 70 |
echo 'graph_scale yes' |
| 71 |
echo 'graph_category network' |
| 72 |
echo 'graph_info This graph shows the bandwidth between localhost and serveral hosts' |
| 73 |
for host in $hosts; do |
| 74 |
fieldname="host_$(clean_fieldname "$host")" |
| 75 |
echo "$fieldname.label $host" |
| 76 |
echo "$fieldname.draw LINE2" |
| 77 |
echo "$fieldname.info Bandwidth statistics for $host" |
| 78 |
done |
| 79 |
exit 0;; |
| 80 |
autoconf) |
| 81 |
if hash bing 2>/dev/null; then |
| 82 |
echo 'yes' |
| 83 |
exit 0; |
| 84 |
else |
| 85 |
echo 'no (bing not installed)' |
| 86 |
exit 0; |
| 87 |
fi |
| 88 |
|
| 89 |
esac |
| 90 |
|
| 91 |
|
| 92 |
#Calculating the bandwidth |
| 93 |
for host in $hosts; do |
| 94 |
fieldname="host_$(clean_fieldname "$host")" |
| 95 |
printf "$fieldname.value "; |
| 96 |
|
| 97 |
SPEED=$(timeout 6 bing localhost "$host" -n -c 1 -e "$samples" -s "$small_packet_size" -S "$big_packet_size" 2>/dev/null \ |
| 98 |
|grep "estimated link" -A 2 \ |
| 99 |
| grep bps \ |
| 100 |
| awk '{print $2}' \
|
| 101 |
| cut -d "b" -f1) |
| 102 |
|
| 103 |
if (echo "$SPEED" | grep -q "M"); then |
| 104 |
echo "$SPEED" | awk '{a+=$1} END{print a*1000000}'
|
| 105 |
elif (echo "$SPEED" | grep -q "K"); then |
| 106 |
echo "$SPEED" | awk '{a+=$1} END{print a*1000}'
|
| 107 |
elif (echo "$SPEED" | grep -q "G"); then |
| 108 |
echo "$SPEED" | awk '{a+=$1} END{print a*1000000000}'
|
| 109 |
else |
| 110 |
echo "Error: no data (timeout)" >&2 |
| 111 |
fi |
| 112 |
done |
