在nagios上安装mongodb_check监控mongodb

1.安装check_mongodb.py
yum install git
cd /usr/local/nagios/libexec/
wget --no-check-certificate https://github.com/mzupan/nagios-plugin-mongodb/archive/master.zip
unzip master 
mv nagios-plugin-mongodb-master nagios-plugin-mongodb
chown -R nagios.nagios nagios-plugin-mongodb/

2. 安装Mongo Python驱动
下载:https://bitbucket.org/pypa/setuptools/get/default.tar.gz#egg=setuptools-dev
tar -xvf pypa-setuptools-5c8ce4511aa5.tar.gz
cd pypa-setuptools-5c8ce4511aa5
python setup install

安装pymongo
git clone git://github.com/mongodb/mongo-python-driver.git pymongo
cd pymongo/
python setup.py install
或者:
wget --no-check-certificate https://github.com/mongodb/mongo-python-driver/archive/master.zip
unzip master.zip
cd mongo-python-driver-master
python setup.py install


3. 测试驱动安装:

[mongodb_f003 nagios-plugin-mongodb]#./check_mongodb.py  --help
Usage: check_mongodb.py [options]

This Nagios plugin checks the health of mongodb.

Options:
  -h, --help            show this help message and exit
  -H HOST, --host=HOST  The hostname you want to connect to
  -P PORT, --port=PORT  The port mongodb is runnung on
  -u USER, --user=USER  The username you want to login as
  -p PASSWD, --pass=PASSWD
                        The password you want to use for that user
  -W WARNING, --warning=WARNING
                        The warning threshold we want to set
  -C CRITICAL, --critical=CRITICAL
                        The critical threshold we want to set
  -A ACTION, --action=ACTION
                        The action you want to take
  --max-lag             Get max replication lag (for replication_lag action
                        only)
  --mapped-memory       Get mapped memory instead of resident (if resident
                        memory can not be read)
  -D, --perf-data       Enable output of Nagios performance data
  -d DATABASE, --database=DATABASE
                        Specify the database to check
  --all-databases       Check all databases (action database_size)
  -s, --ssl             Connect using SSL
  -r, --replicaset      Connect to replicaset
  -q QUERY_TYPE, --querytype=QUERY_TYPE
                        The query type to check
                        [query|insert|update|delete|getmore|command] from
                        queries_per_second
  -c COLLECTION, --collection=COLLECTION
                        Specify the collection to check
  -T SAMPLE_TIME, --time=SAMPLE_TIME
                        Time used to sample number of pages faults

4. 定义nagios command
[mongodb_f002 etc]#vi /usr/local/nagios/etc/objects/commands.cfg  
define command {
        command_name    check_mongodb
        command_line    /etc/nagios/command/nagios-plugin-mongodb/check_mongodb.py -H $HOSTADDRESS$ -A $ARG1$ -P $ARG2$ -W $ARG3$ -C $ARG4$
        }
5 加入mongo监控的配置
vi hosts.cfg
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Mongodb-Linux
        service_description             mongodb
        check_command                   check_mongodb!connect!30000!10!30
        notifications_enabled           1
        }
       
6. 检查配置
./bin/nagios -v ./etc/nagios.cfg 
7.重启nagios reload
service nagios restart

原文地址:https://www.cnblogs.com/xingxingge/p/14726171.html