网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

nagios监控流量-创新互联

监控机:192.168.10.133

站在用户的角度思考问题,与客户深入沟通,找到南岗网站设计与南岗网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:做网站、网站建设、企业官网、英文网站、手机端网站、网站推广、域名与空间、虚拟空间、企业邮箱。业务覆盖南岗地区。

被监控机:192.168.10.107

系统:centos 6.5_x64

1、在监控端安装和测试snmp

2、获取被监控端的网卡信息(用于脚本中的-I参数)

[root@wqk1 mnt]# ./check_traffic.sh -V 2c -C public -H 192.168.10.107 -L

List Interface for host 192.168.10.107.

Interface index 1 orresponding to  lo

Interface index 2 orresponding to  eth0  //使用这个网卡接口

Interface index 3 orresponding to  sit0

3、在监控端和被监控端放置脚本

cd /usr/local/nagios/libexec

chmod +x /usr/local/nagios/libexec/check_traffic.sh

./check_traffic.sh -h

./check_traffic.sh -V 2c -C public -H 192.168.10.107 -I 2 -w 200,300 -c 400,500 -K –B 定义in和out值分别超过200K、300K警告,超过400K,500k严重警告。(第一次运行没有输出,30s后第二次运行才有输出;-I后面的2对应 上面获得的被监控端的网卡信息)

OK - It's the first time for this plugins run. We'll get the data from the next time.

第一次执行,history data file(/var/tmp/check_traffic_${Host}_${Interface}.hist_dat)不存在,因此会由此提示,可以忽略,再执行一次可以正正常获取

4、在监控端command文件里面定义check_traffic命令

# 'check_traffic' command definition

define command{

  command_name  check_traffic

  command_line $USER1$/check_traffic.sh -V 2c -C  public -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -K -B  监控单位可以自定义

}

5、在监控端localhost.cfg中定义主机

vim /usr/local/nagios/etc/objects/localhost.cfg

define host {

    host_name    wqk_centos-107

    alias      centos-107

    address     192.168.10.107

    check_command  check-host-alive

    notification_options   d,u,r

    check_interval  1

    max_check_attempts    2

    contact_groups  admins

    notification_interval  10

    notification_period   24x7

}

6、在监控端localhost.cfg中定义服务

vim /usr/local/nagios/etc/objects/localhost.cfg

define service {

    host_name    wqk_centos-107

    service_description   check_traffic

    check_period   24x7

    normal_check_interval  2

    retry_check_interval   1

    max_check_attempts    5

    notification_period   24x7

    notification_options   w,u,c,r

    check_command   check_nrpe!check_traffic  //与command文件中的名字一样

7、检查测试

cd /usr/local/nagios/libexec

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

8、重启服务

service nagios restart

******************

1、在被监控端安装和测试snmp

参考:http://151wqooo.blog.51cto.com/2610898/1176730

2、插件

cd /usr/local/nagios/libexec

chmod +x /usr/local/nagios/libexec/check_traffic.sh

3、定义命令

编辑nrpe配置文件:

vim /usr/local/nagios/etc/nrpe.cfg

添加:

command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 2 -w 200,300 -c 400,500 -K –B

4、重启服务

ps aux | grep nrpe

kill掉nrpe 进程

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d  //启动nrpe服务

5、远程测试

在监控端

cd /usr/local/nagios/libexec

./check_nrpe -H 192.168.10.107 -c check_traffic

The check interval must greater than 30 Seconds. But now it's 1. Please retry it later.

[root@wqk1 libexec]# ./check_nrpe -H 192.168.10.107 -c check_traffic

OK - The Traffic In is 0.0KB, Out is 0.0KB, Total is 0.0KB. The Check Interval is 60s |In=0.0KB;200;400;0;0 Out=0.0KB;300;500;0;0 Total=0.0KB;500;900;0;0 Interval=60s;1200;1800;0;0

第一次运行没有输出,30s后第二次运行才有输出

[root@wqk1 mnt]# ./check_traffic.sh -V 2c -C public -H 192.168.10.107 -I 2 -w 200,300 -c 400,500 -K –B

OK - The Traffic In is 1Kbps, Out is 0.0Kbps, Total is 1Kbps. The Check Interval is 1165s |In=1Kbps;200;400;0;0 Out=0.0Kbps;300;500;0;0 Total=1Kbps;500;900;0;0 Interval=1165s;1200;1800;0;0

[root@wqk1 mnt]# ./check_traffic.sh -V 2c -C public -H 192.168.10.107 -I 2 -w 0,0 -c 400,500 -K –B

Warning - The Traffic In is 0.0Kbps, Out is 0.0Kbps, Total is 0.0Kbps. The Check Interval is 54s |In=0.0Kbps;0;400;0;0 Out=0.0Kbps;0;500;0;0 Total=0.0Kbps;0;900;0;0 Interval=54s;1200;1800;0;0

[root@wqk1 mnt]# ./check_traffic.sh -V 2c -C public -H 192.168.10.107 -I 2 -w 300,400 -c 400,500 -K –B

OK - The Traffic In is 0.0Kbps, Out is 0.0Kbps, Total is 0.0Kbps. The Check Interval is 68s |In=0.0Kbps;300;400;0;0 Out=0.0Kbps;400;500;0;0 Total=0.0Kbps;700;900;0;0 Interval=68s;1200;1800;0;0

[root@wqk1 mnt]# ./check_traffic.sh -V 2c -C public -H 192.168.10.107 -I 2 -w 500,600 -c 800,900 -K –B

OK - The Traffic In is 0.0Kbps, Out is 0.0Kbps, Total is 0.0Kbps. The Check Interval is 68s |In=0.0Kbps;500;800;0;0 Out=0.0Kbps;600;900;0;0 Total=0.0Kbps;1100;1700;0;0 Interval=68s;1200;1800;0;0

对比红色数字字体——为监控设置的阀值,后面为实际流量值,这就是监控点。

==================

执行命令报错:

./check_nrpe -H 192.168.10.249 -c check_traffic -t 30

Unknown - Read or Write File /var/tmp/check_traffic_127.0.0.1_2.hist_dat_root__64 Error with user uid=500(nagios) gid=500(nagios) groups=500(nagios) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023.

解决:

是因为以非nagios用户身份,手动测试执行过该脚本(也就是command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H ***.***.***.*** -I 2 -w 200,300 -c 400,500 -K -B这个操作),请在正式使用该脚本前,删除被监控端/var/tmp下对应测试生成的/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件,否则会造成nagios用户无法读写该文件的错误

===================

check_traffic.sh只能监控到某一个网卡的全部流量,一旦nagios流量过高,出现警告,如何排查那个进程所占用的流量

可以使用nethogs工具,可以监控某块网卡上每个进程的流量,可以使用nethogs工具自行写个脚本,监控你所关心的进程流量,配合check_traffic.sh插件使用

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章名称:nagios监控流量-创新互联
网站路径:http://bjjierui.cn/article/dppjcs.html

其他资讯