nagios监控linux网卡流量(check_traffic.sh)
1、安装所需组件
yum install perl perl-develperl-CPANbc net-snmpd net-snmp-utils-y
perl -MCPAN -eshell &cpan> install Bundle::LWP
编译安装nrpe(参考教程:http://2860664.blog.51cto.com/2850664/1559056)
以下是被监控端设置
2、下载check_traffic.s脚本
下载地址:https://codeload.github.com/cloved/check_traffic/zip/v1.3.11
解压文件后,上传check_traffic.sh到/usr/local/nagios/libexec
chmod +xcheck_traffic.sh
chown nagios.nagcmdcheck_traffic.sh
3、设置snmp参数
vi /etc/snmp/snmpd.conf
com2secnotConfigUser被监控端IPpublicgroupnotConfigGroupv1notConfigUsergroupnotConfigGroupv2cnotConfigUserviewsystemviewincluded.1.3.6.1.2.1.1viewsystemviewincluded.1.3.6.1.2.1.25.1.1accessnotConfigGroup""anynoauthexactallnonenoneviewallincluded.180syslocationUnknown(edit/etc/snmp/snmpd.conf)syscontactRoot<root@localhost>(configure/etc/snmp/snmp.local.conf)
service snmpd start
chkconfig snmpd on
4、在被监控端测试脚本
cd/usr/local/nagios/libexec
./check_traffic.sh -V 2c -C public -H 192.168.1.247 -I 2 -w 1200,1500 -c 1700,1800 -K -B
OK - The Traffic In is 0.72KB, Out is 0.60KB, Total is 1.32KB. The Check Interval is 43s |In=0.72KB;1200;1700;0;0 Out=0.60KB;1500;1800;0;0 Total=1.32KB;2700;3500;0;0 Interval=43s;1200;1800;0;0
其中红色为被监控端的IP地址。
4、vi /usr/local/nagios/etc/nrpe.cfg添加
command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh-V 2c -C public -H192.168.1.247-I 2 -w 1200,1500 -c 1700,1800 -K -B
以下是nagios主机的设置
5、服务器端测试
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.247 -c check_traffic
OK - The Traffic In is 0.48KB, Out is 0.11KB, Total is 0.59KB. The Check Interval is 28s |In=0.48KB;1200;1700;0;0 Out=0.11KB;1500;1800;0;0 Total=0.59KB;2700;3500;0;0 Interval=28s;1200;1800;0;0
vi /usr/local/nagios/etc/nagios.cfg 添加
cfg_file=/usr/local/nagios/etc/objects/nginx.cfg
6、touch/usr/local/nagios/etc/objects/nginx.cfg
vi/usr/local/nagios/etc/objects/nginx.cfg (注意修改被监控端的IP)内容如下
****************************************我是分割线************************************
definehost{uselinux-serverhost_namenginxaliasnginxaddress被监控端IP}defineservice{usegeneric-servicehost_namenginxservice_descriptioncheck-swapcheck_commandcheck_nrpe!check_swap}defineservice{usegeneric-servicehost_namenginxservice_descriptioncheck-loadcheck_commandcheck_nrpe!check_load}defineservice{usegeneric-servicehost_namenginxservice_descriptioncheck-diskcheck_commandcheck_nrpe!check_sda1}defineservice{usegeneric-servicehost_namenginxservice_descriptioncheck-userscheck_commandcheck_nrpe!check_users}defineservice{usegeneric-servicehost_namenginxservice_descriptionotal_procscheck_commandcheck_nrpe!check_total_procs}defineservice{usegeneric-service;Nameofservicetemplatetousehost_namenginxservice_descriptionPINGcheck_commandcheck_ping!100.0,20%!500.0,60%}defineservice{usegeneric-servicehost_namenginxservice_descriptionnginx_statuscheck_commandcheck_nrpe!check_nginx!notifications_enabled0}defineservice{usegeneric-servicehost_namenginxservice_descriptionnetwork_trafficcheck_commandcheck_nrpe!check_traffic!notifications_enabled0}
****************************************我也是分割线************************************
报错信息
7、nagios服务器报错
Unknown - Read or Write File /var/tmp/check_traffic_192.168.1.247_2__itnms.hist_dat_64 Error with user uid=501(nagios) gid=503(nagcmd) groups=502(nagios),503(nagcmd).
解决方法:chmod nagios.nagcmd/var/tmp/check_traffic_192.168.1.247_2__itnms.hist_dat_64
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。