Navigation
Artikel
Stuff
RSS Feeds
|
Sourcecodes - check_traffic_byprocSprachenübersicht/Bash/Nagios Keywords: check traffic bandwidth proc nagios script Das Skript stammt eigentlich orginal von Nagios Exchange, da es jedoch nicht aktualisiert wird, veröffentliche ich diese Änderung nun hier.
check_traffic: #!/bin/bash # Maintainer Sebastian Clanzett 07/2006 <Sebastian.Clanzett@gmx.de> # Check Interface Traffic Plugin for Linux: Version 0.8 # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # Revision: # - 01/08 2006 > added: monitoring traffic exceeds # - 23/08 2006 > added: Performance data (written to temp_files in /tmp/) # - 24/08 2006 > added: init-Mode: must be started once for each interface # - 03/10 2006 > added: new check style to fix problems with interfaces not named ethX; left old style for compat-reasons # - 14/05 2008 > glua: respect integer overflow VERSION=0.8 function show_usage(){ echo "" echo " Plugin for checking interface traffic based on proc-Filesystem" echo " It now needs a first time initilisation to create the first performance-data by issuing:" echo " $0 init <INTERFACE>" echo "" echo " Usage: $0 <INTERFACE> <--- shows Traffic (compat-mode)" echo " Usage: $0 int <INTERFACE> <-- shows traffic" echo " Usage: $0 maxtx <MAX-TRANCEIVED-BYTES> <INTERFACE> <--- checks Traffic" echo "" echo " Example: $0 maxtx 120000000 eth0 <----- critical when TX-Bytes greater than 12000000 Bytes" echo "" echo " Performance Data Output: DIFF_TX(RX) <- difference between now and last check(bytes) LAST <- last check before xy seconds" echo "" echo "" echo " Version: $VERSION" echo "" } function check_traffic() { INT=$1 AWK=`which awk` MAXTX=$2 TX=`cat /proc/net/dev | grep $INT | $AWK '{ if ($1 == "$INT:") { print $10 } else { print $9 } }'` if [ $MAXTX -lt $TX ]; then DIFF=`expr $TX - $MAXTX` kDIFF=`expr $DIFF / 1024` mDIFF=`expr $kDIFF / 1024` echo "CRITICAL: Traffic limit has exceeded by $kDIFF KBytes or $mDIFF MB!" else echo "Traffc for $INT is OK. Max-Traffic: $MAXTX" fi } function init() { INT=$1 AWK=`which awk` RX=`cat /proc/net/dev | grep $INT | $AWK '{ if ($1 == "$INT:") { print $2 } else { split($1,feld,":");print feld[2]} }'` TX=`cat /proc/net/dev | grep $INT | $AWK '{ if ($1 == "$INT:") { print $10 } else { print $9 } }'` DATE=`date +%s` # save new data echo $TX > /tmp/tx_$INT echo $RX > /tmp/rx_$INT date +%s > /tmp/last_$INT echo "" echo "First time initilisation for $INT completed." echo "" } function show_traffic() { INT=$1 AWK=`which awk` # save old data OLD_TX=`cat /tmp/tx_$INT` OLD_RX=`cat /tmp/rx_$INT` LAST=`cat /tmp/last_$INT` RX=`cat /proc/net/dev | grep $INT | $AWK '{ if ($1 == "$INT:") { print $2 } else { split($1,feld,":");print feld[2]} }'` TX=`cat /proc/net/dev | grep $INT | $AWK '{ if ($1 == "$INT:") { print $10 } else { print $9 } }'` DATE=`date +%s` # save new data echo $TX > /tmp/tx_$INT echo $RX > /tmp/rx_$INT date +%s > /tmp/last_$INT DIFF_TX=`expr ${TX} - ${OLD_TX}` DIFF_RX=`expr ${RX} - ${OLD_RX}` DIFF_AGE=`expr ${DATE} - ${LAST}` if [ $DIFF_TX -lt 0 ]; then DIFF_TX=$(( $DIFF_TX + 4294967295 )); fi if [ $DIFF_RX -lt 0 ]; then DIFF_RX=$(( $DIFF_RX + 4294967295 )); fi echo "$INT TX: $TX Bytes RX: $RX Bytes | DIFF_TX=$DIFF_TX;DIFF_RX=$DIFF_RX;LAST=$DIFF_AGE; " exit 0 } if [ -z "$1" ]; then show_usage exit 2 fi case $1 in --help) show_usage exit 0 ;; int) if [ -z $2 ];then echo "Usage: $0 int <interface>" else INT=$2 show_traffic $INT fi ;; eth*) INT=$1 show_traffic $INT ;; maxtx) INT=$3 MAXTX=$2 check_traffic $INT $MAXTX ;; init) INT=$2 init $INT ;; *) show_usage exit 1 ;; esac
Gibt es noch irgendwelche Fragen, oder wollen Sie über den Artikel diskutieren? Sprachenübersicht/Bash/Nagios/check_traffic_byproc |