来自:网络
安装snmp
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| 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 nagios培训 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 文件中添加
?
1
2
3
4
| 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$
}
|
检测自己网卡型号
?
1
2
3
4
| [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后面的数字就是你要监控网卡的代号 可以自己通过命令先执行一下: ?
1
| /usr/local/nagios/libexec/check_traffic.sh -V 2c -C mypublic -H 192.168.0.156 -I 2 -w 10,10 -c 30,30
|
?
1
2
3
4
5
6
7
| V 代表snmp版本
C 代表community的名称
H 代表主机IP
I 代表网卡号
w 警告
c 紧急
补充:10,10 30,30(代表in,out)
|
输出: ?
1
| 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 nagios实施
|
如果你跟我一样报错
?
1
2
3
| [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
|
请修改
?
1
2
3
4
5
6
7
8
9
| 解决:
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
|
添加服务
?
1
2
3
4
5
6
7
| 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.cf
添加
?
1
| 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
|
监控页面显示服务未知?
?
1
| 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即可
?
1
2
3
4
5
6
7
8
9
10
11
12
| [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
?
1
2
3
4
| 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$
}
|
定义服务
?
1
2
3
4
5
6
| 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 nagios配置 }
|
单位默认是Kbps
监控window主机
首先安装snmp 安装方式 开始—>控制面板---找到简单网络管理协议SNMP 打勾--确定-开始安装 应该需要重启。
然后开始运行services.msc 找到snmp server 服务 右键属性 安全 社区添加一个名字 用来验证 我的是mypubic 接受来自那些主机 填你的nagios server 即可
查看服务器网卡序列
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| [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主机获取流量信息。第一次可能很慢
?
1
2
3
4
5
6
| [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. nagios安装
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 添加主机和服务
?
1
2
3
4
5
6
| define service{
use generic-service,srv-pnp
host_name winserver
service_description Network
check_command check_traffic!12!100!100!300!300
}
|
检测看有没有语法错误。
重启nagios 看监控页面
想做Nagios, Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流 QQ群号 :476809427
|