Nagios 网卡流量监控
本文所用到的監控流量插件來自”石頭”的 1.20 版 shell 插件。感謝之。。。。
下載地址為: 點擊下載 。 總體設置可以分為兩塊, linux 主機及非 linux 主機。稍有出入。不多說直接上配置
一、 linux主機
主要步驟:
| 1、安裝snmpd服務軟件包并設置啟動之。 2、上傳監控插件至被監控機nagios/libexec目錄并授權 3、網卡參數檢測 4、 nrpe.cfg文件增加監控command 5、 nagios服務器配置service.cfg添加監控項 |
具體實施:
1、 安裝修改啟動snmpd服務
安裝:[root@nagios nagios]# yum -y install net-snmp*
| Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Setting up Install Process Package 1:net-snmp-devel-5.3.2.2-9.el5_5.1.i386 already installed and latest version Package 1:net-snmp-libs-5.3.2.2-9.el5_5.1.i386 already installed and latest version Package 1:net-snmp-utils-5.3.2.2-9.el5_5.1.i386 already installed and latest version Package 1:net-snmp-perl-5.3.2.2-9.el5_5.1.i386 already installed and latest version Package 1:net-snmp-5.3.2.2-9.el5_5.1.i386 already installed and latest version Nothing to do #我已經安裝過了。。就上面這些包了。。 |
修改snmpd.conf
| # sec.name source community com2sec notConfigUser 127.0.0.1(localhost也可不改) XXXX(共同體名) # group context sec.model sec.level prefix read write notif access notConfigGroup “” any noauth exact mib2 none none #改system為mib2 view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc #去掉前面的”#”注釋符 |
2、上傳插件被授權
上傳check_traffic.sh至/usr/local/nagios/libexec
改屬主為:nagios
| chown nagios.nagios ./check_traffic.sh |
3、網卡參數檢測:
[root@OAServer etc]# /usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -L
| List Interface for host 127.0.0.1. Interface index 1 orresponding to lo Interface index 2 orresponding to bond0 Interface index 3 orresponding to eth0 Interface index 4 orresponding to eth1 Interface index 5 orresponding to sit0 |
可以測試是否能夠正常采集到數據
/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 2 -w 1200,1500 -c 1700,1800 -K -b
| OK – The Traffic In is 356Kbps, Out is 414Kbps, Total is 770Kbps. The Check Interval is 30s |In=356Kbps;1200;1700;0;0 Out=414Kbps;1500;1800;0;0 Total=770Kbps;2700;3500;0;0 Interval=30s;1200;1800;0;0 |
注:-V snmp協議版本
-C 共同體名
-I 參數對應上面-L輸出的網卡index值。標示監視相應的網卡。
該插件其它使用方法及各參數解釋詳情”-help”或者看上面論壇石頭描述
更改/var/tmp/check_traffic* 文件權限為nagios用戶可讀寫。簡單的給個777吧。。
| chmod 777 /var/tmp/check_traffic_127.0.0.1_2.hist_dat_root__32 |
4、 更改nrpe.cfg增加如下行:
| command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 2 -w 300,350 -c 500,600 -K -B |
重啟nrpe程序
| [root@OAServer ~]# ps aux |grep nrpe nagios 2822 0.0 0.0 4808 1448 ? Ss Jun01 0:04 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d root 1123 0.0 0.0 5936 736 pts/2 S+ 11:02 0:00 grep nrpe [root@OAServer ~]# kill -9 2822 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d |
5、nagios服務器(監控端)編輯service.cfg增加監控網卡流量項目;
| define service{ host_name WEB service_description check_traffic check_command check_nrpe!check_traffic max_check_attempts 5 normal_check_interval 3 retry_check_interval 2 check_period 24×7 notification_interval 10 notification_period 24×7 notification_options w,u,c,r contact_groups sagroup } |
二、其它設備:(win主機、交換、路由、防火墻)
這些主機上都是沒辦法安裝nrpe插件的。所 以我們只有通過snmp協議采集。(兩者異同之處就在于snmp數據報文是否在網絡傳輸。前者snmp數據只會在本機產生,自己采集自身數據而后由 nrpe插件傳輸到nagios服務器前端顯示出來(數據文件在本機)。后者則是nagios服務器通過snmp協議采集目標主機信息而后前端顯示(數據 文件在服務器)。就安全性而言,前者更優于后者。
主要步驟:
| 1、設置主機snmp協議(共同體名、權限、trap目標主機) 2、nagios服務器snmp連接測試及網卡參數確定 3、nagios服務器commands.cfg配置 4、service.cfg監控項目添加 5、重啟nagios服務測試 |
具體實施:
演示設備:windows2003、netscreen防火墻、H3C路由以及H3C交換機。
1、 設置主機snmp協議
Windows主機:添加snmp組件。。在服務里找到”snmp service”編輯如下:
防火墻:
路由器:
交換機:
| snmp-agent snmp-agent local-engineid 800063A2000FE2CCFAA36877 snmp-agent community write XXXXX snmp-agent sys-info version all snmp-agent target-host trap address udp-domain XXXXXX params securityname XXXXX |
1、 nagios服務器snmp連接測試及網卡參數確定:
以防火墻為例,找到個接口參數:
| [root@nagios nagios]# /usr/local/nagios/libexec/check_traffic.sh -V 2c -C ksense -H 192.168.20.254 -L List Interface for host 192.168.20.254. Interface index 1 orresponding to ethernet0/0 Interface index 2 orresponding to ethernet0/1 Interface index 3 orresponding to ethernet0/2 Interface index 4 orresponding to ethernet0/3 Interface index 5 orresponding to vlan1 注意:index 后數字和網卡對應關系。后面寫service.cfg時需用到。 |
2、 配置commands.cfg增加如下內容:
| [root@nagios nagios]# tail -8 /usr/local/nagios/etc/commands.cfg ####################################################################### # #check_traffic # ####################################################################### define command{ command_name check_traffic command_line $USER1$/check_traffic.sh -V 2c -C ksense -H $HOSTADDRESS$ -I $ARG1$ $ARG2$ $ARG3$ -K -B } |
3、 service.cfg監控項目添加:
以防火墻設備為例,其它方法相同
| define service{ host_name juniper-ssg-320 service_description check_traffic_trust check_command check_traffic!1 -w 600,600 -c 800,800 #注:嘆號后面數據對應上面的”$ARG1$ $ARG2$ $ARG3$”3個字段,中間空格隔開 max_check_attempts 5 normal_check_interval 3 retry_check_interval 2 check_period 24×7 notification_interval 10 notification_period 24×7 notification_options w,u,c,r contact_groups sagroup } define service{ host_name juniper-ssg-320 service_description check_traffic_DMZ check_command check_traffic!2 -w 600,600 -c 800,800 max_check_attempts 5 normal_check_interval 3 retry_check_interval 2 check_period 24×7 notification_interval 10 notification_period 24×7 notification_options w,u,c,r contact_groups sagroup } define service{ host_name juniper-ssg-320 service_description check_traffic_untrust1 check_command check_traffic!3 -w 600,600 -c 800,800 max_check_attempts 5 normal_check_interval 3 retry_check_interval 2 check_period 24×7 notification_interval 10 notification_period 24×7 notification_options w,u,c,r contact_groups sagroup } define service{ host_name juniper-ssg-320 service_description check_traffic_untrust2 check_command check_traffic!4 -w 600,600 -c 800,800 max_check_attempts 5 normal_check_interval 3 retry_check_interval 2 check_period 24×7 notification_interval 10 notification_period 24×7 notification_options w,u,c,r contact_groups sagroup } |
5、
| [root@nagios nagios]# !1025 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg ……………… Total Warnings: 0 Total Errors: 0 檢查下配置文件是否有報錯。。。沒有就重啟nagios服務即可生效了。 |
監控效果圖:
Pnp圖形:
轉載于:https://www.cnblogs.com/huangjingzhou/articles/2140122.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的Nagios 网卡流量监控的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 好代码、坏代码之一
- 下一篇: » 欄位太小以致於無法接受您試圖加入的資