Nagios監控window主機和LInux主機網卡流量
安裝snmp
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 文件中添加
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$ }
檢測自己網卡型號
[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后面的數字就是你要監控網卡的代號
可以自己通過命令先執行一下:
/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
請修改
解決: 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 }
我這是通過NRPE監控遠程LInux主機所以這個check_traffic腳本先放到遠程linux主機/usr/local/nagios/libexec下,然后修改/usr/local/nagios/etc/nrpe.cf
添加
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 看監控頁面
本文由用戶 n342 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!