nagios監控流量指令碼

來源:互聯網
上載者:User

標籤:

需求是我們需要對伺服器上的流量進行監控,網路上有個流傳的check_traffic.sh,它需要被監控機開啟snmp。但是感覺都使用上了nagios還要開snmp。。。有點斧子剪刀一起用的感覺,所以就動手寫了個監控流量的shell:

 

#!/bin/shusage() { echo "Usage: $0 [-n <eth0>] [-w <tx rx>] [-c <tx rx>]" 1>&2; exit 1; }foundw=0;foundc=0;foundn=0;for item in [email protected] ; do    if [[ $foundn == 1 ]]; then        n=$item;        foundn=2;        continue;    fi    if [[ $foundw == 1 ]]; then        w1=$item;        foundw=2;        continue;    fi    if [[ $foundw == 2 ]]; then        w2=$item;        foundw=3;        continue;    fi    if [[ $foundc == 1 ]]; then        c1=$item;        foundc=2;        continue;    fi    if [[ $foundc == 2 ]]; then        c2=$item;        foundc=2;        continue;    fi    if [[ "$item" == "-w" ]]; then        foundw=1;        continue;    fi    if [[ "$item" == "-c" ]]; then        foundc=1;        continue;    fi    if [[ "$item" == "-n" ]]; then        foundn=1;        continue;    fidoneif [ -z "${w1}" ] || [ -z "${w2}" ] || [ -z "${c1}" ] || [ -z "${c2}" ] || [ -z "${n}" ]; then    usagefiR1=`cat /sys/class/net/$n/statistics/rx_bytes`T1=`cat /sys/class/net/$n/statistics/tx_bytes`sleep 1R2=`cat /sys/class/net/$n/statistics/rx_bytes`T2=`cat /sys/class/net/$n/statistics/tx_bytes`TBPS=`expr $T2 - $T1`RBPS=`expr $R2 - $R1`TMBPS=`expr $TBPS / 1024 / 128`RMBPS=`expr $RBPS / 1024 / 128`if [[ $TMBPS -ge $c1 ]] || [[ $RMBPS -ge $c2 ]] ; then    echo "Critical - current is ${TMBPS}, ${RMBPS}";    exit 2;fiif [[ $TMBPS -ge $w1 ]] || [[ $RMBPS -ge $w2 ]] ; then    echo "WARNING - current is ${TMBPS}, ${RMBPS}";    exit 1;fiecho "OK - current is ${TMBPS}, ${RMBPS}";exit 0;

其中的w和c的數值單位都是Mb。

nagios監控流量指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.