1. check_icmp
简单地来说 默认我们使用的check_ping 插件是获取不到性能数据PING ok – Packet loss = 0%, RTA = 0.80 ms 这个就是默认check_ping得出来的结果check_icmp是check_ping的扩展,加了性能数据,check_icmp得到的结果如下:
PING ok – Packet loss = 0%, RTA = 0.80 ms |percent_packet_loss=0, rta=0.80
现在我们要在command.cfg中添加command,我的配置:
define command{
command_name check_icmp
command_line $USER1$/check_icmp -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -n 10
}
下面就在nagios 监控对象中添加icmp的选项
define service{
use generic-service ; Name of service template to use
host_name huzi
service_description PING
check_command check_icmp!100.0,20%!500.0,60%
}
保存退出,然后重新加载nagios服务
service nagios reload
可能出错:
check_icmp权限不够,无法执行
cd /usr/local/nagios/libexec (我的插件目录在这里)
chown root:nagios check_icmp
chmod 4711 check_icmp
再重新加载nagios服务
service nagios reload
2.mongodb
网上已经有人写好了mongodb的nagios监控脚本,参考:https://github.com/mzupan/nagios-plugin-mongodb/blob/master/README.md
1) 先安装git
yum install git
或
http://www.kernel.org/pub/software/scm/git/去下载一个吧。选择git-1.7.1.tar.gz(24-Apr-2010 02:38 2.9M )
1.2 安装Git
(1) #tar xvzf git-1.6.6.tar.gz
(2) #cd git-1.6.6
(3) #./configure --prefix=/usr/local
说明:配置安装路径,git 将会安装到/usr/local 目录下
(4) #make
(5) #make install
2) 下载脚本
cd /etc/nagios/command
git clonegit://github.com/mzupan/nagios-plugin-mongodb.git
cd nagios-plugin-mongodb/
chmod 755 check_mongodb.py
如果执行报下面的错误:
# ./check_mongodb.py --help
need to install pymongo
需要安装pymongo:
git clonegit://github.com/mongodb/mongo-python-driver.git pymongo
cd pymongo/
python setup.py install
3) 修改nagios配置,加入这个命令
vi objects/commands.cfg
# 'check_mongodb' command definition连接数
define command {
command_name check_mongodb_connections
command_line $USER1$/check_mongodb.py -H $HOSTADDRESS$ -A connections -P $ARG1$ -W$ARG2$ -C $ARG3$
}
#内存
define command {
command_name check_mongodb_memory
command_line $USER1$/check_mongodb.py -H $HOSTADDRESS$ -A memory -P $ARG1$ -W $ARG2$-C $ARG3$
}
4) 加入mongo监控的配置
vi services.cfg
define service{
use generic-service ; Name ofservice template to use
host_name ..
service_description mongodb_master_check_mongodb_connections
check_command check_mongodb_connections!5080!100!300
notifications_enabled 1
}
define service{
use generic-service ; Name of service template to use
host_name ..
service_description mongodb_master_check_mongodb_memory
check_command check_mongodb_memory!5080!10!30
notifications_enabled 1
}
5) 没错的话,重载nagios就行了。
nagios -v /etc/nagios/nagios.cfg
service nagios reload
3. mysql
本监控为基于nagios服务器主动监控方法,利用check_mysql_health实现多种监控模式:
connection-time (Time toconnect to the server)
uptime (Time the server is running)
threads-connected (Number ofcurrently open connections)线程数
threadcache-hitrate (Hit rate of thethread-cache)慢查询
slave-lag (Seconds behind master)
slave-io-running (Slave iorunning: Yes)主从热备
slave-sql-running (Slave sql running:Yes)主从热备
qcache-hitrate (Query cache hitrate)
qcache-lowmem-prunes (Query cache entries prunedbecause of low memory)
keycache-hitrate (MyISAM keycache hitrate)
bufferpool-hitrate (InnoDB buffer poolhitrate)
bufferpool-wait-free (InnoDB buffer pool waits forclean page available)
log-waits (InnoDB log waits because of a too small log buffer)
tablecache-hitrate (Table cache hitrate)
table-lock-contention (Table lock contention)锁表率
index-usage (Usage of indices)
tmp-disk-tables (Percentof temp tables created on disk)
slow-queries (Slow queries)
long-running-procs (long running processes)
cluster-ndbd-running (ndnd nodes are up and running)
sql (any sql command returning a single number)
具体步骤如下:
1、安装
#wget http://labs.consol.de/wp-content/uploads/2009/10/check_mysql_health-2.1.tar.gz
#tar -zxvf check_mysql_health-2.1.tar.gz
#cd check_mysql_health-2.1
#./configure --prefix=/usr/local/nagios --with-nagios-user=nagios--with-nagios-group=nagios --with-perl=/usr/bin/perl
#make && make install
2、命令测试
#cd /usr/local/nagios/libexec
#./check_mysql_health --hostname 192.168.0.1 --port 3306 --username myname--password mypassword --mode threads-connected --warning 700 --critical 1000
当出现Can'tlocate DBI.pm的错误时:
#yum install perl-DBI perl-DBD-MySQL -y
再次执行,结果如下:
OK - 607 client connection threads | threads_connected=607;700;1000
命令参数:
–hostname <hostname>
Der Datenbankserver, der überwacht werden soll. Im Falle von"localhost" kann dieser Parameter weggelassen werden.
–username <username>
Der Datenbankuser.
–password <password>
Dessen Passwort.
–mode <modus>
Mit dem mode-Parameter teilt man dem Plugin mit, was es tun soll.
–name <objektname>
Hier kann die Prüfung auf ein einziges Objekt begrenzt werden.
–name2 <string>
Verwendet man –mode=sql, dann erscheint das SQL-Statement in der Ausgabe undden Performancedaten.
–warning <range>
–critical <range>
–environment <variable>=<wert>
–method <connectmethode>
Mit diesem Parameter teilt man dem Plugin mit, wie es sich zur Datenbankverbinden soll.
–units <%|KB|MB|GB>
3、nagios命令、服务配置
#vi /usr/local/nagios/etc/objects/commands.cfg
...
#'check_mysql_health'
define command{
command_name check_mysql_health
command_line $USER1$/check_mysql_health --hostname $ARG1$ --port $ARG2$ --username $ARG3$--password $ARG4$ --mode $ARG5$ --warning $ARG6$ --critical $ARG7$ #可以将$ARG1$换成$HOSTADDRESS$
}
...
#vi/usr/local/nagios/etc/objects/servers/localhost.cfg
...
define service{
use local-service ; Name of servicetemplate to use
host_name myhostname
service_description check_mysql_connections
check_command check_mysql_health!192.168.0.1!3306!myname!mypassword!threads-connected!1000!1500
}
define service{
use local-service ; Name of servicetemplate to use
host_name myhostname
service_description check_mysql_table_lock
check_command check_mysql_health!192.168.0.1!3306!myname!mypassword!table-lock-contention!1!2
}
...
4、重启nagios服务
#service nagios restart
4.iostate
#官方默认插件中并无此插件,但官方还是提供了这个插件的下载,地址在
http://www.ofn.dk/files/software/check_iostat
#注意:保证所有被监控机上都安装了sysstat包,并可以执行iostat命令
#下载之后,放在每台被监控机的/usr/local/nagios/libexec/目录下
#然后更改属组,赋予可执行权限
chown nagios:nagios /usr/local/nagios/libexec/check_iostat
chmod 755 !$
#被监控机上更改nrpe的配置文件
vi /usr/local/nagios/etc/nrpe.cfg
#增加下边这两行,如果有更多磁盘,相应增加即可,至于警告和严重警告的值,请适当调整
#—————————-引用文字-开始—————————-
command[check_sda_iostat]=/usr/local/nagios/libexec/check_iostat -d sda -w 100-c 200
可能报错Can't locate Nagios/Plugin.pm in @INC (@INC contains:/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8/usr/lib/perl5/site_perl/usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at./check_iostat line 24.
方法一:
下载rpmforge-release 包。选择以下两个链接中匹配你的 OS 架构(i386/x86_64)的那个下载。如果不能确定是那种架构,请运行 uname -i 命令。
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm
rpm -ivh rpmforge-release-0.5.1-1.el5.rf.i386.rpm--force
yum check-update
yum install -yperl-Params-Validate perl-Math-Calc-Units perl-Regexp-Commonperl-Class-Accessor perl-Config-Tiny perl-Nagios-Plugin.noarch
方法二:
先安装如下模块,或者跟据错误提示安装相关模块:
wget http://search.cpan.org/CPAN/authors/id/T/TO/TONVOON/Nagios-Plugin-0.34.tar.gz
wget http://search.cpan.org/CPAN/authors/id/D/DR/DROLSKY/Params-Validate-0.95.tar.gz
wget http://search.cpan.org/CPAN/authors/id/S/SF/SFINK/Math-Calc-Units-1.07.tar.gz
wget http://search.cpan.org/CPAN/authors/id/A/AB/ABIGAIL/Regexp-Common-2.122.tar.gz
wget http://mirrors.xmu.edu.cn/CPAN/authors/id/K/KA/KASEI/Class-Accessor-0.31.tar.gz
wget http://mirrors.xmu.edu.cn/CPAN/authors/id/A/AD/ADAMK/Config-Tiny-2.12.tar.gz
下载后,在被监控机上(也可以监控机上,就是监控本机)解压安装:
perl Makefile.PL ;make && make install
在被监控机上/usr/local/nagios/etc/nrpe.cfg配置文件里添加
command[check_iostat]=/usr/local/nagios/libexec/check_iostat-w 5 -c 10
把脚本check_iostat放到被监控机的/usr/local/nagios/libexec/目录下,并赋权限
chmod +x/usr/local/nagios/libexec/check_iostat
Chown nagios:nagios/usr/local/nagios/libexec/check_iostat
测试:[root@Rs-02 libexec]# ./check_iostat -w 5 -c 10
IOSTAT OK - user 0.54 nice 0.01 sys 1.41 iowait 1.37 idle 0.00 |iowait=1.37%;; idle=0.00%;; user=0.54%;; nice=0.01%;; sys=1.41%;;
在监控机/usr/local/nagios/etc/objects/commands.cfg里面添加
vim commands.cfg
#iostate
define command {
command_name check_iostat
command_line $USER1$/check_iostat -w $ARG1$ -c $ARG2$
}
vim services.cfg
#iostat
define service{
use generic-service ; Name ofservice template to use
hostgroup_name linux-servers ;可以使用组,单个用户就host_name,以逗号间隔
service_description check_iostat
check_command check_iostat!100!200
notifications_enabled 1
}
/usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg
service nagios reload
但是在此需要使用nrpe来完成:
被监控机安装Nagios-plugins,nrpe
scp 121.9.213.96:/dist/dist/nagios-plugins-1.4.15.tar.gz./
scp 121.9.213.96:/dist/dist/nrpe-2.8.1.tar.gz./
useraddnagios
tar -zxvfnagios-plugins-1.4.15.tar.gz
cdnagios-plugins-1.4.15
./configure--prefix=/usr/local/nagios
make&& make install
chown -Rnagios.nagios /usr/local/nagios/
cd ..
tar -xvfnrpe-2.8.1.tar.gz
cdnrpe-2.8.1
./configure
make all
makeinstall-plugin
makeinstall-daemon
makeinstall-daemon-config
sed "$(sed -n '/allowed_hosts/='/usr/local/nagios/etc/nrpe.cfg) s/$/,121.9.213.96/"/usr/local/nagios/etc/nrpe.cfg|tee /usr/local/nagios/etc/nrpe.cfg.bak
rm -f/usr/local/nagios/etc/nrpe.cfg
cp/usr/local/nagios/etc/nrpe.cfg.bak /usr/local/nagios/etc/nrpe.cfg
echo"command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 100 -c200">>/usr/local/nagios/etc/nrpe.cfg
localip=$(echo$PS1|awk '{print $1}'|cut -d'_' -f4)
echo"server_address=$localip ">>/usr/local/nagios/etc/nrpe.cfg
scp121.9.213.96:/usr/local/nagios/libexec/check_iostat /usr/local/nagios/libexec/
chownnagios.nagios /usr/local/nagios/libexec/check_iostat
chmod 755/usr/local/nagios/libexec/check_iostat
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
rpm -ivh rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm--force
yumcheck-update
yuminstall -y perl-Params-Validate perl-Math-Calc-Units perl-Regexp-Commonperl-Class-Accessor perl-Config-Tiny perl-Nagios-Plugin.noarch
/usr/local/nagios/bin/nrpe-c /usr/local/nagios/etc/nrpe.cfg -d
tail/var/log/messages
在监控机上:
vimcommands.cfg
#iostat
definecommand {
command_name check_iostat
command_line $USER1$/check_iostat -W $ARG1$ -C $ARG2$
}
#nrpe
definecommand {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c$ARG1$
}
vimservices.cfg
defineservice{
use generic-service
host_name *****
service_description iostat
check_command check_nrpe!check_iostat
}
转载请注明文章转自:良玉的博客 [http://blog.uouo123.com]