nagios监控window主机和LInux主机网卡流量

安装snmplinux

yum install net-snmp
修改以下
[root@xen 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 <root@localhost> (configure /etc/snmp/snmp.local.conf)
dontLogTCPWrappersConnects yes


首先将check_triffic.sh脚本拷贝到/usr/local/nagios/libexec/里面。而后在/usr/local/nagios/etc/objects/commands.cfg  文件中添加ios

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

检测本身网卡型号shell

[root@xen 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后面的数字就是你要监控网卡的代号vim

能够本身经过命令先执行一下:安全

/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

若是你跟我同样报错网络

[root@xen 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

请修改app

解决:
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

添加服务oop

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
        }

我这是经过NRPE监控远程LInux主机因此这个check_traffic脚本先放到远程linux主机/usr/local/nagios/libexec下,而后修改/usr/local/nagios/etc/nrpe.cfui

添加

command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C mypublic -H 127.0.0.1 -I 2 -w 1200,1500 -c 1700,1800 -K -B

监控页面显示服务未知?

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

[root@www tmp]# pwd
/var/tmp
[root@www tmp]# ll
总用量 32
-rw-r--r-- 1 nagios nagios   34 4月  28 13:00 check_traffic_192.168.0.137_12__itnms.hist_dat_32
-rw-r--r-- 1 nagios nagios   34 4月  28 11:48 check_traffic_192.168.0.137_18__itnms.hist_dat_32
-rw-r--r-- 1 nagios nagios   34 4月  28 11:48 check_traffic_192.168.0.137_19__itnms.hist_dat_32
-rw-r--r-- 1 nagios nagios   34 4月  28 11:48 check_traffic_192.168.0.137_23__itnms.hist_dat_32
-rw-r--r-- 1 nagios nagios   34 4月  28 11:49 check_traffic_192.168.0.137_24__itnms.hist_dat_32
-rw-rw-r-- 1 nagios nagios   15 4月  28 11:44 check_traffic_192.168.0.137_3__itnms.hist_dat_32
-rw-r--r-- 1 nagios nagios   32 4月  29 09:34 check_traffic_192.168.0.138_3__itnms.hist_dat_64
drwx------ 3 root   root   4096 4月  28 10:25 kdecache-root

便可恢复看到网卡流量

check_traffic 下载地址http://pan.baidu.com/s/1i3vNlBJ

监控本机网卡流量

先定义command.cf

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

监控window主机

首先安装snmp   安装方式 开始—>控制面板---找到简单网络管理协议SNMP  打勾--肯定-开始安装  应该须要重启。

而后开始运行services.msc 找到snmp server 服务 右键属性 安全 社区添加一个名字 用来验证 个人是mypubic 接受来自那些主机  填你的nagios server 便可

查看服务器网卡序列

[root@www ~]# /usr/local/nagios/libexec/check_traffic.sh -V 2c -C mypublic -H 192.168.0.137 -L   #找到你要监控的网卡  我这里本身是window 7 用的无线  #前提window 主机要安装NSClient++  才能够被监控
List Interface for host 192.168.0.137.
Interface index 1 orresponding to  Software Loopback Interface 1
Interface index 2 orresponding to  WAN Miniport (SSTP)
Interface index 3 orresponding to  WAN Miniport (L2TP)
Interface index 4 orresponding to  WAN Miniport (PPTP)
Interface index 5 orresponding to  WAN Miniport (PPPOE)
Interface index 6 orresponding to  WAN Miniport (IPv6)
Interface index 7 orresponding to  WAN Miniport (Network Monitor)
Interface index 8 orresponding to  WAN Miniport (IP)
Interface index 9 orresponding to  RAS Async Adapter
Interface index 10 orresponding to  WAN Miniport (IKEv2)
Interface index 11 orresponding to  Qualcomm Atheros AR8152/8158 PCI-E Fast Ethernet Controller (NDIS 6.20)
Interface index 12 orresponding to  Broadcom 802.11n ���������   
Interface index 13 orresponding to  Teredo Tunneling Pseudo-Interface
Interface index 14 orresponding to  Microsoft ISATAP Adapter
Interface index 15 orresponding to  Microsoft ISATAP Adapter #2
Interface index 16 orresponding to  Qualcomm Atheros AR8152/8158 PCI-E Fast Ethernet Controller (NDIS 6.20)-QoS Packet Scheduler-0000
Interface index 17 orresponding to  Qualcomm Atheros AR8152/8158 PCI-E Fast Ethernet Controller (NDIS 6.20)-WFP LightWeight Filter-0000
Interface index 18 orresponding to  Broadcom 802.11n ����������-Virtual WiFi Filter Driver-0000
Interface index 19 orresponding to  Broadcom 802.11n ����������-QoS Packet Scheduler-0000
Interface index 20 orresponding to  WAN Miniport (Network Monitor)-QoS Packet Scheduler-0000
Interface index 21 orresponding to  WAN Miniport (IP)-QoS Packet Scheduler-0000
Interface index 22 orresponding to  WAN Miniport (IPv6)-QoS Packet Scheduler-0000
Interface index 23 orresponding to  Broadcom 802.11n ����������-Native WiFi Filter Driver-0000
Interface index 24 orresponding to  Broadcom 802.11n ����������-WFP LightWeight Filter-0000

检测能不能从window主机获取流量信息。第一次可能很慢 

[root@www ~]# /usr/local/nagios/libexec/check_traffic.sh -V 2c -C mypublic -H 192.168.0.137 -I 12  -w 10,10 -c 30,30
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: IF-MIB::ifHCOutOctets.12

Critical - The Traffic In is 11Kbps, Out is 52Kbps, Total is 63Kbps. The Check Interval is 494s |In=11Kbps;10;30;0;0 Out=52Kbps;10;30;0;0 Total=63Kbps;20;60;0;0 Interval=494s;1200;1800;0;0

 

定义window.cf 添加主机和服务

define service{
        use                     generic-service,srv-pnp
        host_name               winserver
        service_description     Network
        check_command           check_traffic!12!100!100!300!300
        }

检测看有没有语法错误。

重启nagios 看监控页面