]>
git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/monitoring/plugins/check_bandwidth
3 # ============================== SUMMARY =====================================
4 #Author : Ken Roulamellah
8 # ===================== INFORMATION ABOUT THIS PLUGIN ========================
10 # This plugin checks the average RX and TX bandwidth utilisation. It use
11 # kbytes as measure unite.
13 # ========================== START OF PROGRAM CODE ===========================
20 interface
=$( ip route | grep default | awk '{print $5}' | head -n1)
21 function print_usage
()
24 echo "$0 [ -i=INTERFACE] [ -ct=COUNT ] -w WARNING -c CRITICAL"
25 echo "This script calculate the average bandwith usage."
26 echo "Default values | interface: ${interface}, counter: 10"
42 echo "Error: Arguments are missing"
47 while [[ $# -gt 0 ]]; do
50 interface
="$(cut -d'=' -f2 <<<"$1")"
54 counter
="$(cut -d'=' -f2 <<<"$1")"
66 printf "\nError: Invalid option '$1'"
73 if [ $warning -lt 0 ] || [ $critical -lt 0 ];
75 echo "Error: You need to specify a warning and critical treshold"
80 grep -q "up" /sys
/class
/net
/$interface/operstate
|| exec echo "$interface: no such device or down"
82 read rx
<"/sys/class/net/$interface/statistics/rx_bytes"
83 read tx
<"/sys/class/net/$interface/statistics/tx_bytes"
86 while [ $i -gt 0 ]; do
88 read newrx
<"/sys/class/net/$interface/statistics/rx_bytes"
89 read newtx
<"/sys/class/net/$interface/statistics/tx_bytes"
92 #echo "new rx :$newrx"
93 rx_cal
=$(bc <<< "scale=2; ($newrx-$rx) / 1000")
94 tx_cal=$(bc <<< "scale=2; ($newtx-$tx) / 1000")
96 sum_rx
=$(bc <<< "scale=2;$sum_rx+$rx_cal")
97 sum_tx
=$(bc <<< "scale=2;$sum_tx+$tx_cal")
99 #echo "$interface {rx: $rx_cal ko/s, tx: $tx_cal ko/s}"
105 avg_rx
=$(bc <<< "scale=2;$sum_rx/$counter")
106 avg_tx
=$(bc <<< "scale=2;$sum_tx/$counter")
112 if [ $(bc <<< "$avg_rx > $critical || $avg_tx > $critical") -eq 1 ]; then
113 echo "$interface CRITICAL - AVG_RX: $avg_rx kb/s, AVG_TX:
114 $avg_tx kb/s | RX="$avg_rx"kbps;0;0;0; TX="$avg_tx"kbps;0;0;0;"
116 elif [ $(bc <<< "$avg_rx > $warning || $avg_tx > $warning") -eq 1 ]; then
117 echo "$interface WARNING - AVG_RX: $avg_rx kb/s, AVG_TX: $avg_tx kb/s | RX="$avg_rx"kbps;0;0;0; TX="$avg_tx"kbps;0;0;0;"
120 echo "$interface - OK AVG_RX: $avg_rx kb/s, AVG_TX: $avg_tx kb/s | RX="$avg_rx"kbps;0;0;0; TX="$avg_tx"kbps;0;0;0;"