设为首页 收藏本站
查看: 1750|回复: 0

nagios监控流量

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-7-13 08:43:25 | 显示全部楼层 |阅读模式

监控机:192.168.10.133

被监控机:192.168.10.107
系统:centos 6.5_x64
1、在监控端安装和测试snmp

2、获取被监控端的网卡信息(用于脚本中的-I参数)
[iyunv@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

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.
[iyunv@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后第二次运行才有输出
[iyunv@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
[iyunv@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
[iyunv@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
[iyunv@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插件使用



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-243322-1-1.html 上篇帖子: nagios安装配置教程详解 下篇帖子: nagios的check_http使用 监控 流量 网卡 信息
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表