nagios监控流量脚本

需求是我们需要对服务器上的流量进行监控,网络上有个流传的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 [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;
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监控流量脚本,布布扣,bubuko.com

时间: 2024-08-04 19:41:38

nagios监控流量脚本的相关文章

nagios监控流量

监控机:192.168.10.133 被监控机:192.168.10.107 系统:centos 6.5_x64 1.在监控端安装和测试snmp 2.获取被监控端的网卡信息(用于脚本中的-I参数) [[email protected] mnt]# ./check_traffic.sh -V 2c -C public -H 192.168.10.107 -L List Interface for host 192.168.10.107. Interface index 1 orresponding

Nagios监控数据脚本记录一下。

#!/bin/bash #PORT=$1 u=$1 w=$2 c=$3 BC=/usr/bin/bc GREP=/bin/grep AWK=/bin/awk HEAD=/usr/bin/head TAIL=/usr/bin/tail #u='http://219.148.23.137:8236/nagios_checkpage.ashx?key=SX_MPC' content=`curl -s $u` #echo $content #echo '-------------------------

nagios监控实用教程

nagios监控实用教程 Nagios作为开源网络监视工具,它不但可以有效的监控内存.流量.数据库使用情况.它还可以Windows.Linux主机状态.本专题收录了有关Nagios监控相关文章,供大家参考学习. 标签:nagios nagios监控 监控工具 阅读量:26196收藏量:8 文章标题 阅读评论 作者 nagios网卡流量监控 trffic.sh 51/0 anyue0072017-04-26 nagios搭建(二):nagios监控windows主机 1203/0 fantefei

nagios监控网络流量

系统版本 [[email protected] libexec]# cat /etc/redhat-release CentOS release 5.6 (Final) 1 安装和配置snmp 1)yum install net-snmp-utils net-snmp net-snmp-libs -y 2)vi /etc/snmp/snmpd.conf 把下面两行的#号去掉 #view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc #view

nagios监控inodes

昨天遇到了inodes满了的故障,http://2860664.blog.51cto.com/2850664/1657711,导致我加班.于是又想到了nagios nagios监控inodes脚本下载地址:https://exchange.nagios.org/directory/Plugins/Network-and-Systems-Management/check_disk_inodes/details 使用格式 Usage: check_disk_inodes [-v] [-h] [-w

nagios 监控 网卡流量 脚本

#!/bin/bash # #Time     : 2014-06-23 #Author   : ftlynx #Function : use NET-SNMP get NIC traffic on nagios. Usage(){ echo "Usage: check_traffic.sh [options]" echo "     -H     Host IP." echo "     -P     net-snmp community string.

自定义 nagios监控脚本

一. 自定义nagios监控脚本 1. 在客户端上创建脚本/usr/local/nagios/libexec/check_disk.sh   :就是监控脚本要在客户端vim  /usr/local/nagios/libexec/check_disk.sh 写入如下内容:(client上)#!/bin/bash#!/bin/bashrow=`df -h |wc -l`for i in `seq 2 $row`do        ava=`df -h |sed -n "$i"p|awk '

Nagios监控Windows的网卡流量

Nagios监控Windows的网卡流量 使用/usr/local/nagios/libexec/中的check_traffic.sh,不但可以监控Linux的网卡流量,也可以监控Windows服务器的流量. 1 Check_traffic.sh用法用法 [[email protected] libexec]#/usr/local/nagios/libexec/check_traffic.sh -h Usage: ./check_traffic.sh [ -v ] [ -6 ] [ -r ] -

通过collectd工具获取虚拟机的nagios监控脚本简单例子

在宿主机上安装collectd工具后,可以通过collectd工具来获取宿主机上的虚拟机的cpu,memery,if-traffic等数据.可以通过nagios监控脚本来实现对这些数据监控. 以下是一个简单的监控虚拟机内存脚本: #!/bin/bash #Desc:to check memory about vm instance STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 COLLECTD_HOME=/usr/loca