redhat--nagios插件--check_traffic.sh
****在被监控主机安装nrpe****
(1)在被监控主机上,增加用户和密码
useradd nagios
passwd nagios
(2)安装nagios插件
tar zxf nagios-plugins-1.4.15.tar.gz(nagios-plugins-1.4.15放任意位置,一般习惯放在/opt目录下)
cd nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios
make
make install
chown nagios:nagios /usr/local/nagios/
chown nagios:nagios /usr/local/nagios/libexec/ -R
(3.1)安装nrpe
tar zxf nrpe-2.12.tar.gz(nrpe-2.12.tar.gz放在任意位置,一般习惯放在/opt目录下)
cd nrpe-2.12
./configure(会默认安装在/usr/local/nagios目录下)
make all
make install-plugin
make install-daemon
make install-daemon-config
(3.2)修改nrpe.conf文件
修改以下内容,将nagios监控主机的ip添加到allowed_hosts字段
allowed_hosts=127.0.0.1,监控主机Ip
否则在监控主机上运行/usr/local/nagios/libexec/check_nrpe -H 远端被监控机ip
时会报以下错误CHECK_NRPE: Error - Could not complete SSL handshake.
(3.3)安装xinetd脚本
在nrpe-2.12目录下执行
make install-xinetd
编辑xinetd脚本
vi /etc/xinetd.d/nrpe
在only_from后面增加监控主机的地址,以空格间隔
only_from = 127.0.0.1,监控主机Ip
编辑/etc/services文件,增加nrpe服务
vi /etc/services
# Local services
nrpe 5666/tcp # nrpe
(3.4)重启xinetd服务
/etc/init.d/xinetd restart
(3.5)启动nrpe服务
检查nrpe服务是否启动
#ps aux|grep nrpe
如果nrpe没有启动,启动nrpe服务
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
再次查看nrpe是否已经启动,端口是否正常监听
netstat -at|grep nrpe
tcp 0 0 *:nrpe *:* LISTEN
netstat -ant | grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
(3.6)测试nrpe是否正常工作
/usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12(正确的返回值)
(3.7)查看nrpe的监控命令
cd /usr/local/nagios/etc/
vi nrpe.cfg
找到可以监控的命令
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
(3.8)在监控主机上检查nrpe是否可以练到远端的nrpe
在监控主机上运行
#/usr/local/nagios/libexec/check_nrpe -H 远端监控主机ip
NRPE v2.12(正确的返回值)
这样远端nrpe安装成功,并保证监控主机可以连接远端的nrpe
****安装check_traffic插件****
(1)下载chech_traffic.sh
chech_traffic.sh并不是nagios-plugins自带插件,所以需要自行下载
下载后,将chech_traffic.sh放在/usr/local/nagios/libexec/chech_traffic.sh
修改chech_traffic.sh的权限为777,用户及用户组为nagios
chmod 777 chech_traffic.sh
choen nagios:nagios chech_traffic.sh
(2)安装并配置chech_traffic.sh的依赖服务
脚本准本好以后
在执行
#/usr/local/nagios/libexec/chech_traffic.sh -V 2c -C public -H ***.***.***.*** -I 2 -w 200,300 -c 400,500 -K -B
提示以下错误:
which: no snmpwalk in (/opt/jdk1.6.0_25/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/dell/srvadmin/bin:/opt/dell/srvadmin/sbin:/root/bin)
Can not found command snmpwalk in you system PATH: /opt/jdk1.6.0_25/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/dell/srvadmin/bin:/opt/dell/srvadmin/sbin:/root/bin, pleas check it
是因为chech_traffic.sh依赖snmp服务
(2.1)安装snmp
如果/etc/下已有snmp文件夹,说明snmp已经安装
若果没有,需要安装snmp
因为是redhat系统,首先选择rpm安装
下载对应版本的snmp
rpm -ivh net-snmp-5.3.2.2-7.el5.x86_64.rpm
提示:libsensors.so.3()(64bit) is needed by package 1:net-snmp-5.3.2.2-7.el5.x86_64
依赖libsensors.so.3()(依赖这个库是因为snmp来依赖其他的一些服务)
选择用yum安装,解决依赖库的问题
yum install net-snmp* -y
得知安装net-snmp依赖以下:
lm_sensors*;beecrypt*;elfutils*
下载相应的rpm包,或是使用yum安装以上,再使用
rpm -ivh net-snmp-5.3.2.2-7.el5.x86_64.rpm 安装,即可安装成功
安装成功后,会有/etc/snmp文件
(2.2)配置snmp.conf
修改以下:
# group context sec.model sec.level prefix read write notif
access notConfigGroup "" any noauth exact mib2 none none
##去掉下面此行行首注释#。
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
备注:有些情况是将snmp.conf里面的以下字段也进行了修改,添加了被监控主机ip
# sec.name source community
com2sec notConfigUser 被监控机ip public
修改了以后再被监控上运行
/usr/local/nagios/libexec/chech_traffic.sh -V 2c -C public -H ***.***.***.*** -L
提示noresponse form ....
于是就将com2sec notConfigUser 被监控机ip public的被监控ip去掉以后,就可以正常运行了
(3)执行check_traffic.sh
/usr/local/nagios/libexec/chech_traffic.sh -V 2c -C public -H ***.***.***.*** -I 2 -w 200,300 -c 400,500 -K -B
-I 2 监控的网卡(2是网卡多对应的index值)
-w 200,300 warning的范围
-c 400,500 critical的范围
-K -B是单位
-H 被监测流量的主机ip
使用/usr/local/nagios/libexec/chech_traffic.sh -V 2c -C public -H ***.***.***.*** -L
可以查看主机的网卡对应的index值
Interface index 1 orrresponding to lo
Interface index 2 orrresponding to eth0
Interface index 3 orrresponding to eth1
使用ifconfig,如果你监控的网卡是eth1,那么-I的参数就是3,即,-I 3
如果执行
#/usr/local/nagios/libexec/chech_traffic.sh -V 2c -C public -H ***.***.***.*** -I 2 -w 200,300 -c 400,500 -K -B
OK - It's the first time for this plugins run. We'll get the data from the next time
说明check_traffic.sh可以在被测机上正确执行了
(4)将check_traffic.sh命令添加到nrpe.conf中
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
保存,重启nrpe服务
在被监控机上执行
/usr/local/nagios/libexec/check_nrpe -H ***.***.***.*** -c check_traffic
可能会提示:
SERVICE ALERT: ***.***.***.***;;traffic;UNKNOWN;SOFT;3;Unknown - Read or Write File /var/tmp/check_traffic_***.***.***.***;_11.hist_dat_root__32 Error with user uid=517(nagios) gid=517(nagios) groups=517(nagios)
是因为以非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用户无法读写该文件的错误
删除/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件后
再次执行
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_traffic
可以看见流量的统计结果
(5)在监控主机上验证的被监控上的check_traffic.sh是否可以成功执行
在监控主机上执行/usr/local/nagios/libexec/check_nrpe -H ***.***.***.*** -c check_traffic
得到流量统计结果,可以将check_traffic配到监控主机的服务里面,在nagios上可以监控到远端主机的流量了
以上check_traffic.sh只能监控到某一个网卡的全部流量,一旦nagios流量过高,出现警告,如何排查那个进程所占用的流量
可以使用nethogs工具,可以监控某块网卡上每个进程的流量,可以使用nethogs工具自行写个脚本,监控你所关心的进程流量,配合check_traffic.sh插件使用
redhat--nagios插件--check_traffic.sh的更多相关文章
- nagios 配置 check_traffic 流量监控模块(被监控端)
安装软件包yum -y install net-snmp*chkconfig nrpe onchkconfig snmpd on 使用SCP命令拷贝 check_traffic.sh 到 / usr/ ...
- nagios 配置 check_traffic 流量监控模块(Server 端)
安装软件包yum -y install net-snmp*chkconfig nrpe onchkconfig snmpd onchkconfig nagios on 修改snmp参数,vi /etc ...
- 使用nagios插件 check_mysql_health 过程中遇到的error
使用nagios插件 check_mysql_health 过程中遇到的error 1.如果在运行监控mysql插件的时候遇到了error安装以下依赖包就可以解决: yum install perl- ...
- nagios 插件ndoutils 安装配置
nagios 插件ndoutils 安装配置 原文地址:http://www.cnblogs.com/caoguo/p/5022645.html # Nagios install ndoutils # ...
- nagios插件nagiosql安装配置
nagios插件nagiosql安装配置 # Nagiosql install [root@Cagios ~]# yum install -y libssh2 libssh-devel [root@C ...
- nagios插件之登陆SBC监控电话数
运行:sbc_calls_status_new auto_ssh_sbc_10_17.sh | auto_ssh_sbc_11_17.sh vi sbc_calls_status_new.c #inc ...
- nagios插件之登陆防火墙实现session监控
ssh_firewall_session.sh -- 登陆防火墙并运行dis session statistics firewall_check_sessions.c -- 调用上面脚本.过滤出ses ...
- 用python 写一个nagios插件 监控http内容(转载)
nagios自带的http-check插件主要是检测地址url是否可以访问,在web+中间件的架构中容易出现url能访问,但是后台中间件拓机的情况,因为最近在自学python,所以写了个脚本检测ur ...
- nagios插件之监控if8接口日志(新接口)
vi check_if8_log.c #include <stdio.h> #include <stdlib.h> #include <string.h> #inc ...
随机推荐
- jsp自定义标签分析
jsp自定义标签的优势体现在于jsp页面上面减少了java代码. jsp自定义标签有三大部分组成,首先是类继承TagSupport,实现doStartTag方法. public int doStart ...
- 时序列数据库武斗大会之TSDB名录 Part 2
[编者按] 刘斌,OneAPM后端研发工程师,拥有10多年编程经验,参与过大型金融.通信以及Android手机操作系的开发,熟悉Linux及后台开发技术.曾参与翻译过<第一本Docker书> ...
- Selenium如何使用自定义的Firefox配置文件?
一.自动保存文件 import os from selenium import webdriver fp = webdriver.FirefoxProfile() fp.set_preference( ...
- docker: "build" requires 1 argument. See 'docker build --help'.
http://bbs.csdn.net/topics/391040030 docker build --tag="ouruser/sinatra:v3" -<Dockerf ...
- [SharePoint 2013 入门教程 2 ] 创建WEB应用程序,网站集,网站
SharePoint 2013 的 Hello World 由大到小 创建WEB应用程序(老母),网站集(儿子),网站(孙子) 直接确定,其余都默认 填入标题,选好模板.网站集 儿子就有了. 点击页 ...
- Linux进程管理知识整理
Linux进程管理知识整理 1.进程有哪些状态?什么是进程的可中断等待状态?进程退出后为什么要等待调度器删除其task_struct结构?进程的退出状态有哪些? TASK_RUNNING(可运行状态) ...
- window下安装composer and yii2
我的环境是集合包xampp 1,下载composer:下载地址https://getcomposer.org/download/, 点击蓝色字体“Composer-Setup.exe” 2,安装com ...
- SqlDataAdapter用法
SqlDataAdapter和SqlCommand区别: SqlCommand就是是命令了,可以用它来执行SQL命令: SqlDataAdapter就是数据适配器了,它是用于在数据源和数据集之间通讯的 ...
- java:synchronized
synchronized:利用上锁实现数据同步,避免多线程操作的情况下,数据出现异常. 另一个线程必须等待当前线程执行完这个代码块以后才能执行该代码块. 一个线程获得了一个对象的同步锁,那这个对象上所 ...
- win32 api ShouCursor 根据内部计数器 是否>= 0 决定是否 显示光标,每true时计数器+1,每false-1
win32 api ShouCursor 根据内部计数器 是否>= 0 决定是否 显示光标,每true时计数器+1,每false-1,编程时true 和 false 的次数容易产生bug.