Nagios Monitor Traffic Script

Source: Internet
Author: User
Tags snmp

Demand is that we need to monitor the traffic on the server, there is a circulating check_traffic.sh on the network, it needs to be monitored by the machine to turn on SNMP. But it feels like you're using Nagios and you have to open SNMP ... A bit of axe scissors together with the feeling, so I wrote a monitor the flow of the shell:

#!/bin/shusage () {echo "Usage: $ [-n <eth0>] [-W &LT;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 $T 2-$T 1 ' rbps= ' expr $R 2-$R 1 ' tmbps= ' expr $TBPS/1024/128 ' rmbps= ' expr $RBPS/10 24/128 ' If [[$TMBPS-ge $c 1]] | | [[$RMBPS-ge $c 2]];    Then echo "Critical-current is ${tmbps}, ${rmbps}"; Exit 2;fiif [[$TMBPS-ge $w 1] | | [[$RMBPS-ge $w 2]];    Then echo "Warning-current is ${tmbps}, ${rmbps}"; Exit 1;fiecho "Ok-current is ${tmbps}, ${rmbps}"; Exit 0;

The values for both W and C are in megabytes.

Nagios Monitor Traffic Script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.