nagios监控流量脚本
2014-12-20 14:51
260 查看
需求是我们需要对服务器上的流量进行监控,网络上有个流传的check_traffic.sh,它需要被监控机开启snmp。但是感觉都使用上了nagios还要开snmp。。。有点斧子剪刀一起用的感觉,所以就动手写了个监控流量的shell:
#!/bin/sh usage() { echo "Usage: $0 [-n <eth0>] [-w <tx rx>] [-c <tx rx>]" 1>&2; exit 1; } foundw=0; foundc=0; foundn=0; for item in $@ ; 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; fi done if [ -z "${w1}" ] || [ -z "${w2}" ] || [ -z "${c1}" ] || [ -z "${c2}" ] || [ -z "${n}" ]; then usage fi R1=`cat /sys/class/net/$n/statistics/rx_bytes` T1=`cat /sys/class/net/$n/statistics/tx_bytes` sleep 1 R2=`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; fi if [[ $TMBPS -ge $w1 ]] || [[ $RMBPS -ge $w2 ]] ; then echo "WARNING - current is ${TMBPS}, ${RMBPS}"; exit 1; fi echo "OK - current is ${TMBPS}, ${RMBPS}"; exit 0; 其中的w和c的数值单位都是Mb。
相关文章推荐
- nagios 流量监控和报警的shell脚本
- nagios监控流量--脚本
- nagios 监控流量(借助脚本)
- nagios 监控 网卡流量 脚本
- nagios监控流量脚本
- linux服务器监控流量sh脚本
- 8.nagios使用check_traffic.sh监控网卡流量(转)
- centos nagios监控linux主机监控内存脚本
- nagios监控fms(借助脚本)
- linux下监控网卡流量的shell脚本
- nagios监控服务器磁盘空间的脚本
- nagios通过脚本对系统进行定制监控
- 【Python运维脚本】Python监控网卡流量
- nagios监控cisco交换机流量
- nagios监控windows网卡流量
- nagios监控网络流量
- 监控网卡流量的脚本
- Nagios 监控网络流量(Windows主机和交换机)
- 一键搭建nagios监控系统之二 脚本解释篇
- 关于nagios监控系统添加主机和服务脚本