使用nagios-plugins-rabbitmq监控RabbitMQ

nagios-plugins-rabbitmq 使用 perl 语言写的,这里需要安装perl 环境

wget -c http://xrl.us/cpanm -O /usr/bin/cpanm
chmod +x /usr/bin/cpanm 
  1. Download check_rabbitmq Nagios Plugin
cd ~
wget --no-check-certificate https://github.com/jamesc/nagios-plugins-rabbitmq/archive/master.zip
unzip nagios-plugins-rabbitmq-master.zip
mv nagios-plugins-rabbitmq-master nagios-plugins-rabbitmq

  1. Install Plugin in Libexec directory
mv nagios-plugins-rabbitmq /usr/local/nagios/libexec
cd /usr/local/nagios/libexec/

chown -R nagios:nagios nagios-plugins-rabbitmq/

cd /usr/local/nagios/libexec/nagios-plugins-rabbitmq/scripts

./check_rabbitmq_server
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.7/i386-linux-thread-multi
  1. Install Nagios::Plugin Perl Module

This RabbitMQ Server Nagios plugin requires the “Nagios::Plugin” perl package, which is a bunch of perl modules that is used for writing Nagios plugin in perl.

Install the Nagios::Plugin perl module as shown below. You can either install perl module from source, or from cpan shell command.

这里缺什么根据提示安装,比如

cpanm

                cpanm Module::Install

CPAN shell

perl -MCPAN -e shell

install Module::Install

#这里使用 perl 安装失败,使用源码安装
cd /usr/save

wget http://search.cpan.org/CPAN/authors/id/T/TO/TONVOON/Nagios-Plugin-0.36.tar.gz

tar xvfz Nagios-Plugin-0.36.tar.gz

cd Nagios-Plugin-0.36

perl Makefile.PL

make

make test

make install
  1. Additional Perl Module Dependencies

In my case, I also needed the following Perl modules for the check_rabbitmq_server plugin to work properly.

Install the following Perl modules that are required from cpan shell as shown below:

cpan> install Math::Calc::Units
cpan> install Config::Tiny
cpan> install JSON
cpan> install Math::Calc::Units
After all the dependecies are installed, check_rabbitmq_server will not give any perl module error, instead you’ll see the following missing argument usage error message:

./check_rabbitmq_server

Usage: check_rabbitmq_server [options] -H hostname
Missing argument: hostname
5. Basic check_rabbitmq Usage

The following will connect to the RabbitMQ server that is running on dev-db server on port 15672, and return an OK message, with “Memory”, “Process”, “FD” and “Sockets” information of the connected RabbitMQ server as shown below.

./check_rabbitmq_server -H "dev-db" --port=15672

RABBITMQ_SERVER OK - Memory OK (1.16%) Process OK (0.02%) FD OK (2.93%) Sockets OK (0.12%) | Memory=1.16%;80;90 Process=0.02%;80;90 FD=2.93%;80;90 Sockets=0.12%;80;90
When the RabbitMQ Server is not up and running, you’ll get the following error message.

6定义nagios command

# vim /usr/local/nagios/etc/objects/commands.cfg  
define command{
	command_name check_rabbitmq_aliveness      
	command_line $USER1$/nagios-plugins-rabbitmq/scripts/check_rabbitmq_aliveness  -H $ARG1$ --port=$ARG2$ -u $ARG3$ -p $ARG4$
}

define command{
	command_name check_rabbitmq_overview      
	command_line $USER1$/nagios-plugins-rabbitmq/scripts/check_rabbitmq_overview  -H $ARG1$ --port=$ARG2$ -u $ARG3$ -p $ARG4$
}

define command{
	command_name check_rabbitmq_queue      
	command_line $USER1$/nagios-plugins-rabbitmq/scripts/check_rabbitmq_queue  -H $ARG1$ --port=$ARG2$ -u $ARG3$ -p $ARG4$ --queue $ARG5$
}

define command{
	command_name check_rabbitmq_objects      
	command_line $USER1$/nagios-plugins-rabbitmq/scripts/check_rabbitmq_objects  -H $ARG1$ --port=$ARG2$ -u $ARG3$
}

7.创建 rabbit 监控项

define service{
    use                     generic-service
    host_name               121.207.22.33
    service_description     check_rabbitmq_aliveness
    normal_check_interval   2
    contact_groups          admin_4
    check_command           check_rabbitmq_aliveness!10.1.22.33!15672!nagioscheck!www.ttlsa.com
    }
 
define service{
    use                     generic-service
    host_name               121.207.22.33
    service_description     check_rabbitmq_queue
    normal_check_interval   2
    contact_groups          admin_4
    check_command           check_rabbitmq_queue!10.1.22.33!15672!nagioscheck!www.ttlsa.com!aliveness-test
    }
posted @ 2017-07-18 18:18  xiaoganghu  阅读(778)  评论(0编辑  收藏  举报