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 <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