安装snmp
yum install net-snmp 修改如下 [[email protected] etc]# grep -v ‘#‘ /etc/snmp/snmpd.conf |grep -v ‘^$‘ com2sec notConfigUser default mypublic com2sec notConfigUser 192.168.0.138 mypublic group notConfigGroup v1 notConfigUser group notConfigGroup v2c notConfigUser view systemview included .1.3.6.1.2.1.1 view systemview included .1.3.6.1.2.1.25.1.1 access notConfigGroup "" any noauth exact all none none view all included .1 80 view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc syslocation Unknown (edit /etc/snmp/snmpd.conf) syscontact Root <[email protected]> (configure /etc/snmp/snmp.local.conf) dontLogTCPWrappersConnects yes
首先将check_triffic.sh脚本拷贝到/usr/local/nagios/libexec/里面。然后在/usr/local/nagios/etc/objects/commands.cfg 文件中添加
define command{ command_name check_traffic command_line $USER1$/check_traffic.sh -V 2c -C mypublic -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$,$ARG3$ -c $ARG4$,$ARG5$ }
识别自己网卡型号
[[email protected] etc]# /usr/local/nagios/libexec/check_traffic.sh -V 2c -C mypublic -H 192.168.0.156 -L List Interface for host 192.168.0.156. Interface index 1 orresponding to lo #1号网卡 Interface index 2 orresponding to eth0 #2号网卡
输出信息中index后面的数字就是你要监控网卡的代号
可以自己通过命令先执行一下:
/usr/local/nagios/libexec/check_traffic.sh -V 2c -C mypublic -H 192.168.0.156 -I 2 -w 10,10 -c 30,30
V 代表snmp版本 C 代表community的名称 H 代表主机IP I 代表网卡号 w 警告 c 紧急 补充:10,10 30,30(代表in,out)
输出:
OK - The Traffic In is 0.11KB, Out is 0.0KB, Total is 0.11KB. The Check Interval is 109s |In=0.11KB;1200;1700;0;0 Out=0.0KB;1500;1800;0;0 Total=0.11KB;2700;3500;0;0 Interval=109s;1200;1800;0;0
如果你跟我一样报错
[[email protected] libexec]# /usr/local/nagios/libexec/check_traffic.sh -V 2c -C mypublic -H 192.168.0.156 -L List Interface for host 192.168.0.156. Interface index = No Such Object available on this agent at this OID
请修改
解决: vim /etc/snmp/snmpd.conf 修改两处: 一处: access notConfigGroup "" any noauth exact all none none 或者 access notConfigGroup "" any noauth exact mib2 none none 二处: view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
添加服务
vim /usr/local/nagios/etc/objects/linuxhost.cfg define service{ use generic-service,srv-pnp ; Name of service template to use host_name linuxhost service_description check_traffic check_command check_nrpe!check_traffic }
监控服务未知?
Unknown - Read or Write File /var/tmp/check_traffic_192.168.0.156_2__itnms.hist_dat_64 Error with user uid=542(nagios) gid=543(nagios) groups=543(nagios),544(nagcmd) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023.
修改其权限为nagios.nagios即可
即可恢复看到网卡流量
check_traffic 下载地址http://pan.baidu.com/s/1i3vNlBJ
监控本机网卡流量
先定义commandcf
define command{ command_name check_traffic command_line $USER1$/check_traffic.sh -V 2c -C mypublic -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$,$ARG3$ -c $ARG4$,$ARG5$ }
定义服务
define service{ use local-service,srv-pnp ; Name of service template to use host_name localhost service_description check_traffic check_command check_traffic!3!100!100!300!300 }
单位默认是Kbps
时间: 2024-10-15 06:51:40