From 49aecf4e0e40eb9820d75a4b2f6f7100bd171c12 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Wed, 11 Jul 2018 20:25:57 +0200 Subject: [PATCH] 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