nagios监控主机网卡流量
来自:网络
安装snmp
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
yum install net-snmp
修改如下
# grep -v '#' /etc/snmp/snmpd.conf|grep -v '^$' com2sec notConfigUserdefault mypublic
com2sec notConfigUser192.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
accessnotConfigGroup "" any noauth exactall 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
# /usr/local/nagios/libexec/check_traffic.sh -V 2c -Cmypublic -H 192.168.0.156 -L List Interface for host 192.168.0.156.
Interface index 1 orresponding tolo #1号网卡 Interface index 2 orresponding toeth0 #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,1030,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
# /usr/local/nagios/libexec/check_traffic.sh -V 2c -Cmypublic -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=/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
# pwd
/var/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
# /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 toSoftware Loopback Interface 1 开源监控软件 Interface index 2 orresponding toWAN Miniport (SSTP)
Interface index 3 orresponding toWAN Miniport (L2TP)
Interface index 4 orresponding toWAN Miniport (PPTP)
Interface index 5 orresponding toWAN Miniport (PPPOE)
Interface index 6 orresponding toWAN Miniport (IPv6)
Interface index 7 orresponding toWAN Miniport (Network Monitor)
Interface index 8 orresponding toWAN Miniport (IP)
Interface index 9 orresponding toRAS Async Adapter
Interface index 10 orresponding toWAN Miniport (IKEv2)
Interface index 11 orresponding toQualcomm Atheros AR8152/8158 PCI-E Fast Ethernet Controller (NDIS 6.20)
Interface index 12 orresponding toBroadcom 802.11n ���������
Interface index 13 orresponding toTeredo Tunneling Pseudo-Interface
Interface index 14 orresponding toMicrosoft ISATAP Adapter
Interface index 15 orresponding toMicrosoft ISATAP Adapter #2 Interface index 16 orresponding toQualcomm Atheros AR8152/8158 PCI-E Fast Ethernet Controller (NDIS 6.20)-QoS Packet Scheduler-0000
Interface index 17 orresponding toQualcomm Atheros AR8152/8158 PCI-E Fast Ethernet Controller (NDIS 6.20)-WFP LightWeight Filter-0000
Interface index 18 orresponding toBroadcom 802.11n ����������-Virtual WiFi Filter Driver-0000
Interface index 19 orresponding toBroadcom 802.11n ����������-QoS Packet Scheduler-0000
Interface index 20 orresponding toWAN Miniport (Network Monitor)-QoS Packet Scheduler-0000
Interface index 21 orresponding toWAN Miniport (IP)-QoS Packet Scheduler-0000
Interface index 22 orresponding toWAN Miniport (IPv6)-QoS Packet Scheduler-0000
Interface index 23 orresponding toBroadcom 802.11n ����������-Native WiFi Filter Driver-0000
Interface index 24 orresponding toBroadcom 802.11n ����������-WFP LightWeight Filter-0000
检测能不能从window主机获取流量信息。第一次可能很慢
?
1
2
3
4
5
6
# /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 看监控页面
uploads/space/2015/0428/121430_ahUU_1769595.png
想做Nagios, Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流QQ群号 :476809427
页:
[1]