Setting special thresholds for bandwidth utilization

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
capgemtools
Posts: 56
Joined: Wed Aug 12, 2020 3:16 pm

Setting special thresholds for bandwidth utilization

Post by capgemtools »

Hello Support,

We have one requirement where the thresholds are little different for bandwidth monitoring. We require an alert when BW utilization crosses 90% and also when it goes below 10%. Would you please help us setting those thresholds for BW utilization service.

Critical > 90%
Warning < 10%
OK = 10% to 90%
Thanks,
Supriya
User avatar
pbroste
Posts: 1288
Joined: Tue Jun 01, 2021 1:27 pm

Re: Setting special thresholds for bandwidth utilization

Post by pbroste »

Hello @Sandeep,

Thanks for reaching out, in testing the best check that I found uses vnstat on Linux os for checking bandwidth.

Code: Select all

#!/bin/bash
# script created by nsc
# usage ./bw_watch bw_warning bw_critical pkt_warning pkt_critical
# bw usage is in kbits/s

if [[ -z $1 ]] || [[ -z $2 ]] || [[ -z $3 ]] || [[ -z $4 ]]
then
        echo "VARIABLES ARE NOT SET!!!"
        echo "usage $0 bw_warning bw_critical pkt_warning pkt_critical"
        echo "bw usage is in kbits/s"
        exit 2
fi

bw_warn=$1
bw_crit=$2
packets_warn=$3
packets_crit=$4

bw_output=$(vnstat -tr 5 -s )
rx_value=$(echo $bw_output | grep -o "rx [[:digit:]]*\.*[[:digit:]]* .bit/s" | cut -f2 -d' ' )
rx_unit=$(echo $bw_output | grep -o "rx [[:digit:]]*\.*[[:digit:]]* .bit/s" | cut -f3 -d' ' )
rx_packets=$(echo $bw_output | grep -o "rx [[:digit:]]*\.*[[:digit:]]* .bit/s [[:digit:]]* packets/s" | cut -f4 -d' ' )
tx_value=$(echo $bw_output | grep -o "tx [[:digit:]]*\.*[[:digit:]]* .bit/s" | cut -f2 -d' ' )
tx_unit=$(echo $bw_output | grep -o "tx [[:digit:]]*\.*[[:digit:]]* .bit/s" | cut -f3 -d' ' )
tx_packets=$(echo $bw_output | grep -o "tx [[:digit:]]*\.*[[:digit:]]* .bit/s [[:digit:]]* packets/s" | cut -f4 -d' ' )

#convert rx to kbits/s
#if [ $rx_unit == "Mbit/s" ]
#then rx_value=`echo "$rx_value * 1024" | bc`
#fi

#convert tx to kbits/s
#if [ $tx_unit == "Mbit/s" ]
#then tx_value=`echo "$tx_value * 1024" | bc`
#fi

#convert to integer
rx_value=${rx_value/.*}
tx_value=${tx_value/.*}


if [ $bw_crit -lt $rx_value ] || [ $bw_crit -lt $tx_value ] || [ $packets_crit -lt $rx_packets ] || [ $packets_crit -lt $tx_packets ]
then
        echo "CRITICAL: RX/TX: $rx_value/$tx_value kbits/s. PKT: RX/TX: $rx_packets/$tx_packets"
        exit 2
elif [ $bw_warn -gt $rx_value ] || [ $bw_warn -gt $tx_value ] || [ $packets_warn -gt $rx_packets ] || [ $packets_warn -gt $tx_packets ]
then
        echo "WARNING: RX/TX: $rx_value/$tx_value kbits/s. PKT: RX/TX: $rx_packets/$tx_packets"
        exit 1
else
        echo "OK: RX/TX: $rx_value/$tx_value kbits/s. PKT: RX/TX: $rx_packets/$tx_packets"
        exit 0
fi
~
In testing we are altering to show that "$bw_crit -lt ...." to -lt some number "less than" and "$bw_warn -gt ...." to -gt some number "greater than". (Note; I commented out the conversion because I did that in my head).


Examples;
  • 1 set to low threshold and 200 for the top end:

Code: Select all

./bw_watch.sh 1 200 1 200
OK: RX/TX: 79/19 kbits/s. PKT: RX/TX: 93/9
Again, these are only examples and further tweaking on the script and the numbers will provide better results. I found this script here. There are others that can be found in the Nagios Plugin Exchange. This will provide the groundwork to work from going forward.

Please let us know if you have further questions,
Perry
Locked