From a1cc26f2d3c0baeb52d13e14823951f14ca63afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Manuel=20Febrer=20Cort=C3=A9s?= Date: Fri, 31 Mar 2017 14:19:14 +0200 Subject: [PATCH 1/8] Update multibandwidth bing have some random spikes. Added a variable that is used to indicate the maximum value of mbps that can be recorded (in bps). --- plugins/network/multibandwidth | 86 +++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth index a7edf4c8..fdb1b994 100755 --- a/plugins/network/multibandwidth +++ b/plugins/network/multibandwidth @@ -1,37 +1,38 @@ -#!/bin/sh - -. "$MUNIN_LIBDIR/plugins/plugin.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 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. +#!/bin/sh + +. "$MUNIN_LIBDIR/plugins/plugin.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 15 +env.small_packet_size 44 +env.big_packet_size 108 +env.max_mbps 15728640 + +- 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. @@ -40,6 +41,8 @@ env.big_packet_size 108 packets. The default is 108. The size should be chosen so that big packet roundtrip times are long enough to be accurately measured. +- env.max_mbps explanation: bing have some random spikes. This variable is used to indicate + the maximum value of mbps that can be recorded (in bps). =head1 MAGIC MARKERS @@ -101,11 +104,20 @@ for host in $hosts; do | cut -d "b" -f1) if (echo "$SPEED" | grep -q "M"); then - echo "$SPEED" | awk '{a+=$1} END{print a*1000000}' + VALUE=`echo "$SPEED" | sed 's/.$//'` + RATE=`echo "$VALUE * 1048576" | bc -l` + + if [ $(echo "$RATE" >= "$max_mbps" | bc >/dev/null && echo "no" || echo "yes") = "yes" ]; then + echo "$max_mbps" + else + echo "$RATE" + fi elif (echo "$SPEED" | grep -q "K"); then - echo "$SPEED" | awk '{a+=$1} END{print a*1000}' + VALUE=`echo "$SPEED" | sed 's/.$//'` + echo "$VALUE * 1024" | bc -l elif (echo "$SPEED" | grep -q "G"); then - echo "$SPEED" | awk '{a+=$1} END{print a*1000000000}' + VALUE=`echo "$SPEED" | sed 's/.$//'` + echo "$VALUE * 1073742000" | bc -l else echo "Error: no data (timeout)" >&2 fi From 1ae4ac09dae4e2b8fcbec46bca0b867be82875df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Manuel=20Febrer=20Cort=C3=A9s?= Date: Tue, 4 Apr 2017 15:48:24 +0200 Subject: [PATCH 2/8] Update multibandwidth I will update more changes in the next days --- plugins/network/multibandwidth | 72 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth index fdb1b994..d0dfe8a2 100755 --- a/plugins/network/multibandwidth +++ b/plugins/network/multibandwidth @@ -1,38 +1,38 @@ -#!/bin/sh - -. "$MUNIN_LIBDIR/plugins/plugin.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 15 -env.small_packet_size 44 -env.big_packet_size 108 -env.max_mbps 15728640 - -- env.hosts explanation: hostname or IP of the hosts to calculate the bandwidth. - -- env.samples explanation: Reset stats after sending samples ECHO_REQUEST packets. +#!/bin/sh + +. "$MUNIN_LIBDIR/plugins/plugin.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 15 +env.small_packet_size 44 +env.big_packet_size 108 +env.max_mbps 15728640 + +- 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. @@ -107,7 +107,7 @@ for host in $hosts; do VALUE=`echo "$SPEED" | sed 's/.$//'` RATE=`echo "$VALUE * 1048576" | bc -l` - if [ $(echo "$RATE" >= "$max_mbps" | bc >/dev/null && echo "no" || echo "yes") = "yes" ]; then + if [ `echo "$RATE > $max_mbps" | bc` -eq "1" ]; then echo "$max_mbps" else echo "$RATE" From 49aecf4e0e40eb9820d75a4b2f6f7100bd171c12 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Wed, 11 Jul 2018 20:25:57 +0200 Subject: [PATCH 3/8] Plugin multibandwidth: simplify speed calculation --- plugins/network/multibandwidth | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth index d0dfe8a2..280c1406 100755 --- a/plugins/network/multibandwidth +++ b/plugins/network/multibandwidth @@ -95,7 +95,6 @@ esac #Calculating the bandwidth for host in $hosts; do 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 \ @@ -103,22 +102,17 @@ for host in $hosts; do | awk '{print $2}' \ | cut -d "b" -f1) - if (echo "$SPEED" | grep -q "M"); then - VALUE=`echo "$SPEED" | sed 's/.$//'` - RATE=`echo "$VALUE * 1048576" | bc -l` - - if [ `echo "$RATE > $max_mbps" | bc` -eq "1" ]; then - echo "$max_mbps" - else - echo "$RATE" - fi - elif (echo "$SPEED" | grep -q "K"); then - VALUE=`echo "$SPEED" | sed 's/.$//'` - echo "$VALUE * 1024" | bc -l - elif (echo "$SPEED" | grep -q "G"); then - VALUE=`echo "$SPEED" | sed 's/.$//'` - echo "$VALUE * 1073742000" | bc -l + 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); }') else echo "Error: no data (timeout)" >&2 fi + if [ "$RATE" -gt "$max_mbps" ]; then + RATE="$max_mbps" + fi + echo "${fieldname}.value $RATE" done From ade6f5f228193bf0e75d4d54fcac0eab1b4d4da5 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Wed, 11 Jul 2018 20:26:20 +0200 Subject: [PATCH 4/8] Plugin multibandwidth: proper handling of invalid values --- plugins/network/multibandwidth | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth index 280c1406..4cbfefe0 100755 --- a/plugins/network/multibandwidth +++ b/plugins/network/multibandwidth @@ -109,6 +109,7 @@ for host in $hosts; do elif echo "$SPEED" | grep -q "G"; then RATE=$(echo "$SPEED" | awk '{ print int($1 * 1024 * 1024 * 1024); }') else + RATE="U" echo "Error: no data (timeout)" >&2 fi if [ "$RATE" -gt "$max_mbps" ]; then From 580a39ed41377e6e704a377807c53b0de929d45e Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Wed, 11 Jul 2018 20:29:31 +0200 Subject: [PATCH 5/8] Plugin multibandwidth: rename environment setting for limiting the valid range --- plugins/network/multibandwidth | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth index 4cbfefe0..810a5725 100755 --- a/plugins/network/multibandwidth +++ b/plugins/network/multibandwidth @@ -28,7 +28,7 @@ env.hosts example.org example2.org example3.org env.samples 15 env.small_packet_size 44 env.big_packet_size 108 -env.max_mbps 15728640 +env.max_valid_bps 15728640 - env.hosts explanation: hostname or IP of the hosts to calculate the bandwidth. @@ -41,7 +41,7 @@ env.max_mbps 15728640 packets. The default is 108. The size should be chosen so that big packet roundtrip times are long enough to be accurately measured. -- env.max_mbps explanation: bing have some random spikes. This variable is used to indicate +- env.max_valid_bps explanation: bing have some random spikes. This variable is used to indicate the maximum value of mbps that can be recorded (in bps). =head1 MAGIC MARKERS @@ -112,8 +112,9 @@ for host in $hosts; do RATE="U" echo "Error: no data (timeout)" >&2 fi - if [ "$RATE" -gt "$max_mbps" ]; then - RATE="$max_mbps" + if [ -n "$max_valid_bps" ] && [ "$RATE" -gt "$max_valid_bps" ]; then + # the value is outside of the allowed range; discard it + RATE="U" fi echo "${fieldname}.value $RATE" done From 5fb2e02eab9b490148491fb1f8d49acb3308231c Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Wed, 11 Jul 2018 20:34:38 +0200 Subject: [PATCH 6/8] Plugin multibandwidth: explicit handling of configuration variables --- plugins/network/multibandwidth | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth index 810a5725..699c2248 100755 --- a/plugins/network/multibandwidth +++ b/plugins/network/multibandwidth @@ -20,7 +20,8 @@ You can install bing by using (Ubuntu/Debian): apt-get install bing =head1 CONFIGURATION -The following is the default configuration +The following example configuration shows all settings. Only "hosts" is required for +minimal configuration. [multibandwidth] user root @@ -30,19 +31,22 @@ env.small_packet_size 44 env.big_packet_size 108 env.max_valid_bps 15728640 -- env.hosts explanation: hostname or IP of the hosts to calculate the bandwidth. +- env.hosts: space separated list of hostnames or IPs of the hosts to calculate the bandwidth. + This setting is required. -- env.samples explanation: Reset stats after sending samples ECHO_REQUEST packets. +- env.samples: Reset stats after sending this number of ECHO_REQUEST packets. + Defaults to 15 samples. -- env.small_packet_size explanation: Specifies the number of data bytes to be sent in the small +- env.small_packet_size: 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 +- env.big_packet_size: 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.max_valid_bps explanation: bing have some random spikes. This variable is used to indicate +- env.max_valid_bps: bing have some random spikes. This variable is used to indicate the maximum value of mbps that can be recorded (in bps). + Defaults to the empty string (no validity check). =head1 MAGIC MARKERS @@ -64,6 +68,12 @@ GPLv2 =cut +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} + case $1 in config) From ecc6e30d55178a134d813c7271976dc2ea1e4498 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Wed, 11 Jul 2018 20:36:49 +0200 Subject: [PATCH 7/8] Plugin multibandwidth: unify whitespace --- plugins/network/multibandwidth | 46 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth index 699c2248..bfd46ca2 100755 --- a/plugins/network/multibandwidth +++ b/plugins/network/multibandwidth @@ -77,37 +77,37 @@ max_valid_bps=${max_valid_bps:-15728640} case $1 in config) - 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;; + 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 + ;; autoconf) - if command -v bing >/dev/null 2>&1; then - echo 'yes' - exit 0; - else - echo 'no (bing not installed)' - exit 0; - fi - + if command -v bing 2>/dev/null; then + echo 'yes' + else + echo 'no (bing not installed)' + fi + exit 0 + ;; esac -#Calculating the bandwidth +# Calculating the bandwidth for host in $hosts; do fieldname="host_$(clean_fieldname "$host")" 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 "estimated link" -A 2 \ | grep bps \ | awk '{print $2}' \ | cut -d "b" -f1) From 14436e808ec6fb8528a5d05ad5d20d09ff4e64f2 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Wed, 11 Jul 2018 20:38:38 +0200 Subject: [PATCH 8/8] Plugin multibandwidth: fix 'applicable systems' documentation hint --- plugins/network/multibandwidth | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/network/multibandwidth b/plugins/network/multibandwidth index bfd46ca2..b7ebfdc6 100755 --- a/plugins/network/multibandwidth +++ b/plugins/network/multibandwidth @@ -10,7 +10,7 @@ multibandwidth - Plugin to monitor the bandwidth between localhost and serveral =head1 APPLICABLE SYSTEMS -All systems with “bash”, and “munin” +All systems with "bing" installed. =head1 REQUIREMENTS