近兩天 在整合公司的監控 要不zabbix上 逐步遷移到 nagios+ganglia平臺上
ios
在網絡監控這塊發現ganglia獲取的信息不能自定義爲Mb(也可能我沒有找對配置位置)vim
從網上 搜索發現 有網友編寫了 traffic.sh的腳本,我就拿來用了api
traffic.sh 下載地址 http://pan.baidu.com/s/1o8PoDBG網絡
進入正題
ide
客戶端 測試
1.安裝snmp組件spa
[root@localhost ~]# yum install -y net-snmp net-snmp-libs net-snmp-utils.net
2.更改配置文件 /etc/snmp/snmpd.confpwa
com2sec notConfigUser default public #改成 監控主機ip插件
access notConfigGroup "" any noauth exact systemview none none # 改成mib2
#view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc # 去除註釋
3.測試鏈接
snmpwalk -v 2c -c public 127.0.0.1 #須要將配置文件ip臨時改成127.0.0.1 正確的話會出現好多內容
服務端
1. 移動check_traffic.sh腳本到 nagios插件目錄,本例位於 /usr/lib64/nagios/plugins/
mv check_traffic.sh /usr/lib64/nagios/plugins/
2.更改腳本權限
chmod 755 check_traffic.sh
3.安裝 bc #報錯信息見error 1
[root@m plugins]# yum install -y bc.x86_64
4.
查看網卡編號
[root@m plugins]# /usr/lib64/nagios/plugins/check_traffic.sh -V 2c -C public -H 10.10.4.41 -L
測試
/usr/lib64/nagios/plugins/check_traffic.sh -V 2c -C public -H 10.10.4.41 -I 2 -w 300,500 -c 600,800 -M -b # -I 2的2爲檢測到的網卡索引號
OK - The Traffic In is 33.38Mbps, Out is 15.28Mbps, Total is 48.66Mbps. The Check Interval is 90s |In=33.38Mbps;300;600;0;0 Out=15.28Mbps;500;800;0;0 Total=48.66Mbps;800;1400;0;0 Interval=90s;1200;1800;0;0
5.添加命令
vim /etc/nagios/objects/commands.cfg
# 'check_traffic' command definition
define command{
command_name check_traffic
command_line $USER1$/check_traffic.sh -V 2c -C public -H $HOSTNAME$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -M -B
}
vim /etc/nagios/objects/api.cfg #本例是在現有的基礎上添加的
define service{
use api-service
hostgroup_name api
service_description check_traffic
notifications_enabled 1
check_command check_traffic!2!300,300!600,600
max_check_attempts 1
}
error 1
[root@m plugins]# /usr/lib64/nagios/plugins/check_traffic.sh -V 2c -C public -H 10.10.4.41 -I 2 -w300,500 -c600,800 -M -b
/usr/lib64/nagios/plugins/check_traffic.sh: line 449: bc: command not found
/usr/lib64/nagios/plugins/check_traffic.sh: line 454: bc: command not found
/usr/lib64/nagios/plugins/check_traffic.sh: line 457: bc: command not found
/usr/lib64/nagios/plugins/check_traffic.sh: line 458: bc: command not found
/usr/lib64/nagios/plugins/check_traffic.sh: line 461: [: too many arguments
/usr/lib64/nagios/plugins/check_traffic.sh: line 576: bc: command not found
/usr/lib64/nagios/plugins/check_traffic.sh: line 577: bc: command not found
解決方法
yum install -y bc
error 2
Unknown - Can not found data in the history data file. Please to check the file /var/tmp/check_traffic_10.10.4.41_2.hist_dat_root__64 ,or use use verbose mode and check the debug file
Unknown是因爲
第一次執行,由於history data file不存在,所以會由此提示,能夠忽略。
若是每次執行都忽略,則要檢查/var/tmp下是否有/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件生成。
文件的內容是系統當前的時間,in及out當前的數值。
在此感謝,兩位大神