nagios服務端 :192.168.5.203
windows被監控端 192.168.5.208
2.打開服務,找到SNMP Service
右擊SNMP Service---屬性---安全---勾選發送身份驗證陷阱,添加團體public,權限讀寫,接受來自任何主機的SNMP數據包---確定
重新啓動SNMP Server
查看UDP161端口是否存在
3.nagios服務器配置
查看是否安裝snmp包
修改snmpd.conf,如下圖
[root@localhost ~]# vim /etc/snmp/snmpd.conf
重啓snmpd
[root@localhost ~]# service snmpd restart
#chkconfig snmpd on
下載check_traffic.sh並上傳到Nagios服務器
1)下載地址http://pan.baidu.com/s/1jGmR1S6 放到 /usr/local/nagios/libexec/ ,並給執行權限
[root@localhost ~]# ll /usr/local/nagios/libexec/check_traffic.sh
-rwxr-xr-x. 1 root root 26150 Mar 22 2012 /usr/local/nagios/libexec/check_traffic.sh
2)在nagios服務器上添加檢測流量的命令
[root@localhost ~]# vim /usr/local/nagios/etc/objects/commands.cfg
-C 後參數爲snmpd.conf裏設置的community 值
-I 大寫i,後跟網卡藉口的index值
-w 後跟網卡in,out流量 超過這個值警告
-c 後跟網卡in,out流量 超過這個值報警
-K -B 單位爲KB
3)添加check_traffic服務
查看被監控端windows的網卡信息,可以看到只有一個網卡,網卡index值爲65539
# /usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 192.168.5.208 -L
List Interface for host 192.168.5.208.
Interface index 1 orresponding to MS TCP Loopback interface
Interface index 65539 orresponding to Realtek RTL8139 Family PCI Fast Ethernet NIC
[root@localhost ~]# vim /usr/local/nagios/etc/objects/windows.cfg
注:services-pnp在安裝pnp纔有效
重啓nagios服務:顯示nagios進程,殺死進程,再啓動進程(建議啓動或停止就以這種方式)
[root@localhost ~]# kill 16464
[root@localhost ~]# /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
訪問監控頁面http://192.168.5.203/nagios 查看
1.如果監控頁面錯誤顯示 Return code of 127 is out of bounds - plugin may be missing
可能原因是添加檢測流量的命令有錯誤,仔細檢查關鍵字 路徑 格式 是否正確
2.如果監控頁面錯誤顯示 解決方法:在nagios服務器 清空 /var/tmp/ 裏的臨時文件 或給/uar/tmp/ 加 777權限
3.測試是否能獲取到被監控機網卡流量數據
[root@localhost local]# /usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 192.168.5.208 -I 65539 -w 200,300 -c 400,500 -K -B
若果正常,第一次測試顯示
OK - It's the first time for this plugins run. We'll get the data from the next time.
第二次纔會顯示採集的數據,例如
OK - The Traffic In is 0.50KB, Out is 0.0KB, Total is 0.50KB. The Check Interval is 625s |In=0.50KB;200;400;0;0 Out=0.0KB;300;500;0;0 Total=0.50KB;500;900;0;0 Interval=625s;1200;1800;0;0