From 26e9009dc51171d53f6caae0be23a0b08b371b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Manuel=20Febrer=20Cort=C3=A9s?= Date: Fri, 10 Mar 2017 15:44:28 +0100 Subject: [PATCH 1/5] multibandwidth Plugin to monitor the bandwidth between localhost and serveral hosts. --- plugins/network/multibandwidth | 97 ++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 plugins/network/multibandwidth diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth new file mode 100644 index 00000000..36ebec84 --- /dev/null +++ b/plugins/network/multibandwidth @@ -0,0 +1,97 @@ +#!/bin/sh + +: <<=cut + +=head1 NAME + +multibandwidth - Plugin to monitor the bandwidth between localhost and serveral hosts. + +=head1 APPLICABLE SYSTEMS + +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 +env.small_packet_size 1000 +env.big_packet_size 8000 + +- env.hosts explanation: hostname or IP of the hosts to calculate the bandwidth. + +- env.samples explanation: Reset stats after sending samples ECHO_REQUEST packets. + +- 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. + +- 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 +Marco Bertola's help + +=head1 LICENSE + +GPLv2 + +=cut + + + +case $1 in + config) + echo graph_title MultiBandwidth + echo 'graph_vlabel Mbps' + echo 'graph_args --base 1000 -l 0' + echo 'graph_scale no' + echo 'graph_category network' + echo 'graph_info This graph shows the bandwidth between localhost and serveral hosts' + for host in $hosts; do + bandwidth=$((bandwidth+1)) + echo 'bandwidth'"$bandwidth"'.label ' "$host" + echo 'bandwidth'"$bandwidth"'.draw LINE2' + echo 'bandwidth'"$bandwidth"'.info Bandwidth statistics for '"$host" + done + exit 0;; + autoconf) + if hash bing 2>/dev/null; then + echo 'yes' + exit 0; + else + echo 'no (bing not installed)' + exit 0; + fi + +esac + + +#Calculating the bandwidth +for host in $hosts; do + bandwidth=$((bandwidth+1)) + printf "%s""bandwidth""$bandwidth"".value "; + #bing output example: host: 4.592Mbps 0.223ms 0.217773us/bit + bing localhost "$host" -n -c 1 -e "$samples" -s "$small_packet_size" -S "$big_packet_size" 2>/dev/null \ + | grep -E "bit$" \ + | cut -d " " -f3 \ + | cut -c -5 \ + | awk '{a+=$1} END{print a/NR}' +done From aa3cd8311c9c57fbd4113c2d0c99c2dda4000e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Manuel=20Febrer=20Cort=C3=A9s?= Date: Mon, 13 Mar 2017 14:14:00 +0100 Subject: [PATCH 2/5] Update multibandwidth --- plugins/network/multibandwidth | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth index 36ebec84..9f6b57c3 100644 --- a/plugins/network/multibandwidth +++ b/plugins/network/multibandwidth @@ -8,7 +8,7 @@ multibandwidth - Plugin to monitor the bandwidth between localhost and serveral =head1 APPLICABLE SYSTEMS -All systems with "bash", and "munin" +This plugin is useful when you want to monitor the bandwidth between localhost and multiple hosts in a single graph or in several graphs making different soft links. =head1 REQUIREMENTS From d638d14a415f1d05f7d2e2efa410556eb575fd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Manuel=20Febrer=20Cort=C3=A9s?= Date: Tue, 14 Mar 2017 11:07:50 +0100 Subject: [PATCH 3/5] Update multibandwidth Correction of a bug with spaces when there was an output of more than 2 digits --- plugins/network/multibandwidth | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth index 9f6b57c3..3f48cd4b 100644 --- a/plugins/network/multibandwidth +++ b/plugins/network/multibandwidth @@ -91,7 +91,7 @@ for host in $hosts; do #bing output example: host: 4.592Mbps 0.223ms 0.217773us/bit bing localhost "$host" -n -c 1 -e "$samples" -s "$small_packet_size" -S "$big_packet_size" 2>/dev/null \ | grep -E "bit$" \ - | cut -d " " -f3 \ + | awk -F" +" '{ print $2}' | cut -c -5 \ | cut -c -5 \ | awk '{a+=$1} END{print a/NR}' done From f679a922d5034a9fdabc95b9d938ebc62db09ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Manuel=20Febrer=20Cort=C3=A9s?= Date: Wed, 22 Mar 2017 15:53:53 +0100 Subject: [PATCH 4/5] Update multibandwidth --- plugins/network/multibandwidth | 41 ++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth index 3f48cd4b..70c3433a 100644 --- a/plugins/network/multibandwidth +++ b/plugins/network/multibandwidth @@ -8,7 +8,7 @@ multibandwidth - Plugin to monitor the bandwidth between localhost and serveral =head1 APPLICABLE SYSTEMS -This plugin is useful when you want to monitor the bandwidth between localhost and multiple hosts in a single graph or in several graphs making different soft links. +All systems with “bash”, and “munin” =head1 REQUIREMENTS @@ -31,9 +31,12 @@ env.big_packet_size 8000 - env.samples explanation: Reset stats after sending samples ECHO_REQUEST packets. -- 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. +- 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. -- 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. +- 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 @@ -47,7 +50,7 @@ env.big_packet_size 8000 =head1 AUTHOR Jose Manuel Febrer Cortés -Marco Bertola's help +Marco Bertola’s help =head1 LICENSE @@ -61,8 +64,8 @@ case $1 in config) echo graph_title MultiBandwidth echo 'graph_vlabel Mbps' - echo 'graph_args --base 1000 -l 0' - echo 'graph_scale no' + 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 @@ -86,12 +89,22 @@ esac #Calculating the bandwidth for host in $hosts; do - bandwidth=$((bandwidth+1)) - printf "%s""bandwidth""$bandwidth"".value "; - #bing output example: host: 4.592Mbps 0.223ms 0.217773us/bit - bing localhost "$host" -n -c 1 -e "$samples" -s "$small_packet_size" -S "$big_packet_size" 2>/dev/null \ - | grep -E "bit$" \ - | awk -F" +" '{ print $2}' | cut -c -5 \ - | cut -c -5 \ - | awk '{a+=$1} END{print a/NR}' + bandwidth=$((bandwidth+1)) + printf "%s""bandwidth""$bandwidth"".value "; + + 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 + echo "$SPEED" | awk '{a+=$1} END{print a}' + elif (echo "$SPEED" | grep -q "K"); then + echo "$SPEED" | awk '{a+=$1} END{print a/1000}' + elif(echo "$SPEED" | grep -q "G"); then + echo "$SPEED" | awk '{a+=$1} END{print a*1000}' + else + echo "Error: no data" + fi done From 1bed50bb642894252960f0f44bad7083488b6b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Manuel=20Febrer=20Cort=C3=A9s?= Date: Thu, 23 Mar 2017 11:15:32 +0100 Subject: [PATCH 5/5] Update multibandwidth --- plugins/network/multibandwidth | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth index 70c3433a..4f4f7298 100644 --- a/plugins/network/multibandwidth +++ b/plugins/network/multibandwidth @@ -1,5 +1,7 @@ #!/bin/sh +. "$MUNIN_LIBDIR/plugins/plugin.sh" + : <<=cut =head1 NAME @@ -24,8 +26,8 @@ The following is the default configuration user root env.hosts example.org example2.org example3.org env.samples 10 -env.small_packet_size 1000 -env.big_packet_size 8000 +env.small_packet_size 44 +env.big_packet_size 108 - env.hosts explanation: hostname or IP of the hosts to calculate the bandwidth. @@ -63,16 +65,16 @@ GPLv2 case $1 in config) echo graph_title MultiBandwidth - echo 'graph_vlabel Mbps' + 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 - bandwidth=$((bandwidth+1)) - echo 'bandwidth'"$bandwidth"'.label ' "$host" - echo 'bandwidth'"$bandwidth"'.draw LINE2' - echo 'bandwidth'"$bandwidth"'.info Bandwidth statistics for '"$host" + fieldname="host_$(clean_fieldname "$host")" + echo "$fieldname.label $host" + echo "$fieldname.draw LINE2" + echo "$fieldname.info Bandwidth statistics for $host" done exit 0;; autoconf) @@ -89,8 +91,8 @@ esac #Calculating the bandwidth for host in $hosts; do - bandwidth=$((bandwidth+1)) - printf "%s""bandwidth""$bandwidth"".value "; + fieldname="host_$(clean_fieldname "$host")" + printf "$fieldname.value "; 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 \ @@ -99,12 +101,12 @@ for host in $hosts; do | cut -d "b" -f1) if (echo "$SPEED" | grep -q "M"); then - echo "$SPEED" | awk '{a+=$1} END{print a}' + echo "$SPEED" | awk '{a+=$1} END{print a*1000000}' elif (echo "$SPEED" | grep -q "K"); then - echo "$SPEED" | awk '{a+=$1} END{print a/1000}' - elif(echo "$SPEED" | grep -q "G"); then echo "$SPEED" | awk '{a+=$1} END{print a*1000}' + elif (echo "$SPEED" | grep -q "G"); then + echo "$SPEED" | awk '{a+=$1} END{print a*1000000000}' else - echo "Error: no data" + echo "Error: no data (timeout)" >&2 fi done