nagios check_mongodb插件监控mongodb

Nagios是一款开源免费的网路监视工具,可以监控的设备:Windows,Linux,Unix,Router,Switch,具有报警功能,是一个网络监控系统。它可以监视你指定的主机和服务,并在那些设备“变坏”和“变好”的时候通知管理员。
在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。Nagios Core 原先设计在Linux下运行,当然,它在其他的Unix系统下应该也能进行工作。
[官方网站:][1]

针对于Nagios,我们需要配合许多组件和插件来工作(打开很慢,需要FQ):
https://www.nagios.org/downloads/nagios-core-frontends/        //Nagios界面很不美观,可以更换主题
https://www.nagios.org/downloads/nagios-core-addons/            //Nagios插件
https://exchange.nagios.org                                                        //各类拓展组件官方网站,包括脚本
https://exchange.nagios.org/directory/Addons                             //监控插件或脚本
 
Nagios运行模式和优点
运行模式:数据收集是C/S模式,用户查看监控信息是B/S模式
优点:    1:监控网路服务状态(HTTPD,FTP,SSH,MySql……)
              2:监控主机资源(处理器符合,硬盘利用率……)
              3:拓展,根据自己的需求实现拓展检测功能(插件开发)
              4:自动日志回滚
              5:具备定义网络分层结构的能力,用“parent”主机定义来表达网络主机间的关系
              6:警告,基于状态的警告:OK,Warning(警告),critical(关键),unknown(未知)
              7:可以支持并实现对主机的冗余监控
              8:WEB界面
Nagios运行原理
Nagios的功能是监控服务和主机,但是他自身并不包括这部分功能,所有的监控、检测功能都是通过各种插件来完成的。
启动Nagios后,它会周期性的自动调用插件去检测服务器状态,同时Nagios会维持一个队列,所有插件返回来的状态信息都进入队列,Nagios每次都从队首开始读取信息,并进行处理后,把状态结果通过web显示出来。
Nagios提供了许多插件,利用这些插件可以方便的监控很多服务状态。安装完成后,在nagios主目录下的/libexec里放有nagios自带的可以使用的所有插件,如,check_disk是检查磁盘空间的插件,check_load是检查CPU负载的,等等。每一个插件可以通过运行./check_xxx –h 来查看其使用方法和功能。

Nagios 通过NRPE 来远端管理服务

  1. Nagios 执行安装在它里面的check_nrpe 插件,并告诉check_nrpe 去检测哪些服务。
  2. 通过SSL,check_nrpe 连接远端机子上的NRPE daemon
  3. NRPE 运行本地的各种插件去检测本地的服务和状态(check_disk,..etc)
  4. 最后,NRPE 把检测的结果传给主机端的check_nrpe,check_nrpe 再把结果送到Nagios状态队列中。
  5. Nagios 依次读取队列中的信息,再把结果显示出来。
    Nagios所需要的软件
     LAMP环境,不需要mysql
    nagios-3.5.1.tar.gz                             #Nagios核心文件,Nagios服务文件,不建议用最新,很多插件没做好
    nagios-plugins-2.1.1.tar.gz                #Nagios 插件,用于存放脚本和命令
    NSCP-0.5.0                                       #也就是Nsclient++,用来监控Windows,分为64为何32位版本
    nrpe-2.15.tar.gz                                #代理服务,用于监控非Nagios服务器的服务器本地私有信息代理
    vautour_style.zip                               #主题包

部署Nagios监控服务器
部署之前,需要做好最基本的环境,包括LAP环境的构建(这里直接使用yum方式安装即可,在做zabbix的时候我么你需要使用我们编译的LNMP环境来做)

解决依赖和安装LAP环境

[root@test ~]# yum install -y gcc glibc glibc-common php gd gd-devel libpng libmng libjpeg zlib
[root@test ~]# yum install -y httpd ; service httpd restart
Nagios运行用户
[root@test ~]# useradd nagios      //建立Nagios用户,这里不能使用nologin的shell,nagios会用到
[root@test ~]# groupadd nagcmd       //建立一个组
 [root@test ~]# usermod -G nagcmd nagios    //将Nagios和apache加入该组
[root@test ~]# usermod -G nagcmd apache
Nagios核心安装
 [root@test ~]# mkdir Nagios            //所有软件包放在此目录下
[root@test ~]# cd Nagios ; ls
    nagios-3.5.1.tar.gz          nrpe-2.15.tar.gz
    nagios-plugins-2.1.1.tar.gz  vautour_style.zip
[root@test Nagios]# tar xvf nagios-3.5.1.tar.gz -C /usr/local/src/
[root@test Nagios]# cd /usr/local/src/nagios/
[root@test]# ./configure  --with-command-group=nagcmd    //指定Nagios运行用户组
……
General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios           #运行用户
       Command user/group:  nagios,nagcmd           #运行用户组
            Embedded Perl:  no
             Event Broker:  yes
        Install ${prefix}:  /usr/local/Nagios     #默认安装到了/usr/local/nagios
                Lock file:  ${prefix}/var/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/rc.d/init.d
  Apache conf.d directory:  /etc/httpd/conf.d       #Apache的conf.d配置文件目录
             Mail program:  /bin/mail
                  Host OS:  linux-gnu
 
 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/        #登陆地址
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  /bin/traceroute
 
 
Review the options above for accuracy.  If they look okay,
type'make all' to compile the main program and CGIs.
[root@test nagios]# make all                     
//根据上面提示,Make all,下图出现,就无问题
** Compile finished ***

If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type'make'
without any arguments for a list of all possible options):         
#下面已经提示安装步骤,我们就使用这个步骤来操作
 
  make install
     - This installs the main program, CGIs, and HTML files
 
  make install-init
     - This installs the init script in /etc/rc.d/init.d
 
  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file
 
  make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You‘ll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!
 
  make install-webconf
     - This installs the Apache config file for the Nagios
       web interface
 
  make install-exfoliation         #主题相关,不需要安装
     - This installs the Exfoliation theme for the Nagios
       web interface
 
  make install-classicui           #主题相关,不需要安装,安装到web-conf就可以了
     - This installs the classic theme for the Nagios
       web interface
 
 
*** Support Notes *******************************************
 
If you have questions about configuring or running Nagios,
please make sure that you:
 
     - Look at the sample config files
     - Read the documentation on the Nagios Library at:
           http://library.nagios.com
 
before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you.  This might include:
 
     - What version of Nagios you are using
     - What version of the plugins you are using
     - Relevant snippets from your config files
     - Relevant error messages from the Nagios log file
 
For more information on obtaining support for Nagios, visit:
 
       http://support.nagios.com
 
*************************************************************
 
Enjoy.

安裝

[root@test nagios]# make install && make install-init && make install-commandmode && make install-config && make install-webconf                                 
         //若是单步执行,每次执行一部,都会提示你下一步需要干什么,非常easy
//make install安装生成/usr/local/nagios/,其中/usr/local/nagios/share即nagiosWEB访问界面的站点目录
//make install-init                    安装生成/etc/rc.d/init.d/nagios  启动脚本                                                       
//make install-config                  安装生成/usr/local/nagios/etc下的nagios相关配置文件                                 
//make install-commandmode   设定相应nagios工作目录的权限
//make install-webconf              安装Nagios的WEB配置文件到Apache的conf.d目录下
 到此时,安装过程就结束了
在安装的时候,make install时生存了share这个目录,这个目录是访问界面目录:

[root@test nagios]# cd /root/Nagios ; ls /usr/local/nagios/share/
config.inc.php  docs    includes   js        media       rss-corefeed.php  side.php  stylesheets
contexthelp     images  index.php  main.php  robots.txt  rss-newsfeed.php  ssi
       在make install-init的时候,生存了启动脚本
[root@test Nagios]# ls /etc/init.d/nagios
/etc/init.d/nagios      #其实就是在/etc/rc.d/init.d/nagios
       在make install-config的时候,生成了Nagios的相关配置文件
 [root@test Nagios]# ls /usr/local/nagios/etc/
cgi.cfg  nagios.cfg  objects  resource.cfg
#包括以后安装了plugin等软件后,配置文件也会放入此目录
  resource.cfg:定义了很多资源变量的调用
       在make install-webconf的时候,已经把web-conf的相配置文件放入了/etc/httpd/conf.d/下面
[root@test Nagios]# ls /etc/httpd/conf.d/nagios.conf
/etc/httpd/conf.d/nagios.conf       #里面配置了一个别名,直接引用了/usr/local/nagios/share目录
[root@test Nagios]# vim /etc/httpd/conf.d/nagios.conf
……
Alias /nagios "/usr/local/nagios/share"
……

Nagios主目录


[root@test Nagios]# ll /usr/local/nagios/
bin             #Nagios执行程序所在目录
etc             #nagios配置文件所在目录,初始安装只有几个*.cfg文件
libexec         #监控所用命令,需要安装了nagios-plugins插件了才会有,检测命令,不装是空的
sbin            #Nagios的Cgi文件所在目录,外部命令所需要的文件存放目录
share           #Nagios前端页面
var             #日志文件,pid文件等
#认识一下nagios的配置文件
[root@test Nagios]# vim /usr/local/nagios/etc/nagios.cfg
log_file=/var/log/nagios/nagios.log                        #日志位置
cfg_file=/etc/nagios/objects/commands.cfg                   #这个文件定义了很多命令
cfg_file=/etc/nagios/objects/contacts.cfg                   #定义联系人,怎么联系
cfg_file=/etc/nagios/objects/timeperiods.cfg                #定义了时间段
cfg_file=/etc/nagios/objects/templates.cfg                  #模板(联系人,主机,时间)
cfg_file=/etc/nagios/objects/localhost.cfg                  #监控本机相关配置文件
#cfg_file=/etc/nagios/objects/windows.cfg                   #windows,默认不监控
#cfg_file=/etc/nagios/objects/switch.cfg                    #交换机路由器监控,默认不监控
#cfg_file=/etc/nagios/objects/printer.cfg                   #打印机监控,默认不监控
 
#cfg_dir=/etc/nagios/servers                                #定义了服务合集(多个使用)
#cfg_dir=/etc/nagios/printers                               #定义了打印机合集(多个使用)
#cfg_dir=/etc/nagios/switches                               #定义了交换合集(多个使用)
#cfg_dir=/etc/nagios/routers                                #定义了路由合集(多个使用) 
resource_file=/etc/nagios/private/resource.cfg 资源变量配置文件,包括$USER1$变量(一个路径)等
status_update_interval=10                                   #状态更新时间,单位s
log_rotation_method=d                                       #日志滚动,默认天
service_check_timeout=60                                    #服务检查超时时间
host_check_timeout=30                                   #主机检查超时时间
event_handler_timeout=30                               
notification_timeout=30
ocsp_timeout=5
perfdata_timeout=5
 [root@test Nagios]# vim /usr/local/nagios/etc/cgi.cfg
//此配置文件比nagios.cfg优先级高
main_config_file= /usr/local/nagios/etc/nagios.cfg             #主配置文件
physical_html_path= /usr/local/nagios/share          #物理路径
url_html_path=/nagios                               #在URL后面加上/nagios才能访问
use_authentication=1                                #使用认证
use_ssl_authentication=0                            #不使用ssl
authorized_for_system_information=nagiosadmin       #认证用户

Nagios前端访问测试

       [root@test Nagios]# service httpd restart

需要用户名和密码,查看vim /etc/httpd/conf.d/nagios.conf配置文件

[root@test Nagios]# vim /etc/httpd/conf.d/nagios.conf
Alias /nagios "/usr/local/nagios/share"
 
<Directory "/usr/local/nagios/share">
#  SSLRequireSSL
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
   AuthName "Nagios Access"             #这三个字段,就是访问nagios的认证用户名和密码相关配置
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user
</Directory>

在Directory字段里面有Auth这三个字段,那么就可以使用htpasswd来生成用户名和密码

[root@test Nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
       -c表示创建,二次添加用户,不能使用-c参数
[root@test Nagios]# cat /usr/local/nagios/etc/htpasswd.users
nagionsadmin:HQolRVjV67MiQ          #密码
[root@test Nagios]# service httpd restart      //再次测试(我的用户名是nagiosadmin,密码123456)
##nagios 默认使用nagiosadmin来管理,如果使用其他用户名,对应的配置文件也要修改

检查配置文件
在nagios的目录下,bin目录下有一个nagios命令,这个命令可以帮助我们对配置文件的检查工作以及指定相关配置文件

[root@test Nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
 -v=--verify-config 验证配置文件是否有误,着重看到下图亮点就没问题
Total Warnings:0
Total Errors:   0 
指定配置文件,以守护进程方式启动
 [root@test Nagios]# /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
#但是现在还没有做任何深入配置,所以现在只是可以登录而已!

安装Nagios-plugins插件

Nagios-plugins含有丰富的检测命令插件,安装完成之后放在了/usr/local/Nagios/libexec下面

[root@test Nagios]# tar xvf nagios-plugins-2.1.1.tar.gz -C /usr/local/src/
[root@test Nagios]# cd /usr/local/src/nagios-plugins-2.1.1/
[root@test nagios-plugins-2.1.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
[root@test nagios-plugins-2.1.1]# make && make install ; cd /root/Nagios/
[root@test Nagios]# ls /usr/local/nagios/libexec/               //已经有了很多check命令
check_apt       check_ftp           check_mailq        check_oracle   check_ssmtp
check_breeze    check_http          check_mrtg         check_overcr   check_swap
check_by_ssh    check_icmp          check_mrtgtraf     check_pgsql    check_tcp
check_clamd     check_ide_smart     check_mysql        check_ping     check_time
check_cluster   check_ifoperstatus  check_mysql_query  check_pop      check_udp
……

启动Nagios服务,检查环境
       [root@XueGod63 Nagios]# service httpd restart ; service nagios restart
浏览器测试:登陆之后,点击hosts,可以看到,默认监控的是本机,说明环境没有什么问题

下面使用nagios-plugin-mongodb来监控MongoDB数据库。[检测库][2]
[2]: https://github.com/mzupan/nagios-plugin-mongodb

  1. 下载check_mongodb nagios插件
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/
  1. 安装Mongo Python驱动
yum install pymongo.x86_64
#或者自己下载源码包编译。
get --no-check-certificate https://github.com/mongodb/mongo-python-driver/archive/master.zip
unzip mongo-python-driver-master.zip
cd mongo-python-driver-master
python setup.py install

3.Nagios MongoDB监控插件的所有动作

connect–默认动作.检查连接

connections–检查打开的数据库连接的百分比

memory–检测内存使用量

memory_mapped–检查映射内存的使用情况

lock–检查锁定时间的百分比

flushing–检查平均flush时间(以微秒)

last_flush_time–检查上次刷新时间(以微秒)

index_miss_ratio–检查索引命中失败率

databases–检查数据库的总数

collections–检查集合的总数

database_size–检查特定数据库的大小

database_indexes–检查特定数据库的索引大小

collection_indexes–检查一个集合的索引大小

replication_lag–检查复制延迟(以秒为单位)

replication_lag_percent–检查复制延迟(以百分比表示)

replset_state–检查副本集的状态

replica_primary–检查副本集的主服务器

queries_per_second–检查每秒查询量

connect_primary–检查连接在一组中的主服务器

collection_state–检查数据库中特定集合的状态

4.定义nagios command
vim /usr/local/nagios/etc/objects/commands.cfg

define command {
    command_name    check_mongodb
    command_line    $USER1$/nagios-plugin-mongodb/check_mongodb.py -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -A $ARG5$ -W $ARG6$ -C $ARG7$
}
 
define command {
    command_name    check_mongodb_database
    command_line    $USER1$/nagios-plugin-mongodb/check_mongodb.py -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -A $ARG5$  -W $ARG6$ -C $ARG7$ -d $ARG8$
}
 
define command {
    command_name    check_mongodb_collection
    command_line    $USER1$/nagios-plugin-mongodb/check_mongodb.py -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -A $ARG5$ -W $ARG6$ -C $ARG7$ -d $ARG8$ -c $ARG9$
}
 
define command {
    command_name    check_mongodb_replicaset
    command_line    $USER1$/nagios-plugin-mongodb/check_mongodb.py -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -A $ARG5$ -W $ARG6$ -C $ARG7$ -r $ARG8$
}
 
define command {
    command_name    check_mongodb_query
    command_line    $USER1$/nagios-plugin-mongodb/check_mongodb.py -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -A $ARG5$ -W $ARG6$ -C $ARG7$ -q $ARG8$
}

5.hosts.cfg主要用来指定被监控的主机地址以及相关属性信息,根据实验目标配置如下:
vim /usr/local/nagios/etc/objects/hosts.cfg

define host{ 
use linux-server #引用主机linux-server的属性信息,linux-server主机在templates.cfg文件中进行了定义。 
host_name rhel-155 #主机名 
alias nagios #主机别名 
address 10.1.11.155 #被监控的主机地址 
icon_image server.gif 
statusmap_image server.gd2  #状态图
2d_coords 100,300    #2D图形坐标
3d_coords 100,300,100 #3D图形坐标
}

define hostgroup{ #主机组并不是必须的,这是配合 nagios 的监控页面的显示

hostgroup_name MongoServers #主机组名称 
alias Linux Servers #主机组别名 
members rhel-155 #主机组成员

}

6.创建监控项
vim /usr/local/nagios/etc/objects/services.cfg

#1.Check Connection 需要监控集群中每台mongodb实例
define service{
    use                generic-service  #引用主机 generic-service的属性信息, generic-service主机在templates.cfg文件中进行了定义。 
    hostgroup_name          MongoServers
    service_description    MongoConnectCheck
    check_command          check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!connect!2!4
}
#2 Check Percentage of Open Connections 检查空闲连接率
define service {
    use                 generic-service
    hostgroup_name          Mongo Servers
    service_description     Mongo Free Connections
    check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!connections!70!80
}
#3 Check Replication Lag 检测复制延迟
defineservice{

    use                generic-service
    hostgroup_name          MongoServers
    service_description    MongoReplicationLag
    check_command          check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!replication_lag!15!30
}
#.4 Check Replication Lag Percentage 检查复制滞后百分比。如果检查达到100%的话就需要完全重新同步。

define service {
    use                 generic-service
    hostgroup_name          Mongo Servers
    service_description     Mongo Replication Lag Percentage
    check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!replication_lag_percent!50!75
}
#5 Check Memory Usage 检查内存使用情况

define service {
    use                 generic-service
    hostgroup_name          Mongo Servers
    service_description     Mongo Memory Usage
    check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!memory!20!28
}
#6 Check Mapped Memory Usage 检查mongodb映射内存使用情况
define service {
    use                 generic-service
    hostgroup_name          Mongo Servers
    service_description     Mongo Mapped Memory Usage
    check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!memory_mapped!20!28
}
#7 Check Lock Time Percentage 检查锁定时间百分比。如果有锁定时间通常意味着数据库已经超载

define service {
    use                 generic-service
    hostgroup_name          Mongo Servers
    service_description     Mongo Lock Percentage
    check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!lock!5!10
}
#8 Check Average Flush Time 检查平均刷新时间。如果平均刷新时间高就意味着数据库存在大量写。

define service {
    use                 generic-service
    hostgroup_name          Mongo Servers
    service_description     Mongo Flush Average
    check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!flushing!100!200
}
#9 Check Last Flush Time 检查最后刷新时间。如果最后刷新时间高就意味着服务器可能存在IO压力,需要更换更快的磁盘。
define service {
    use                 generic-service
    hostgroup_name          Mongo Servers
    service_description     Mongo Last Flush Time
    check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!last_flush_time!200!400
}
#10 Check status of mongodb replicaset 检查的MongoDB replicaset状态
define service {
      use                     generic-service
      hostgroup_name          Mongo Servers
      service_description     MongoDB state
      check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!replset_state!0!0
}
#11 Check status of index miss ratio 检查索引命中失败率。如果该值高,需要考虑添加索引了。
define service {
      use                     generic-service
      hostgroup_name          Mongo Servers
      service_description     MongoDB Index Miss Ratio
      check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!index_miss_ratio!.005!.01
}
#12 Check number of databases and number of collections

define service {
      use                     generic-service
      hostgroup_name          Mongo Servers
      service_description     MongoDB Number of databases
      check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!databases!300!500
}
 
define service {
      use                     generic-service
      hostgroup_name          Mongo Servers
      service_description     MongoDB Number of collections
      check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!collections!300!500
}
#13 Check size of a database 检查数据库的大小。跟踪数据增长率。
define service {
      use                     generic-service
      hostgroup_name          Mongo Servers
      service_description     MongoDB Database size db_ttlsa_posts
      check_command           check_mongodb_database!10.1.11.155!27017!check_mongodb!www.ttlsa.com!database_size!300!500!db_ttlsa_posts
}
#14 Check index size of a database 检查数据库的索引大小

define service {
      use                     generic-service
      hostgroup_name          Mongo Servers
      service_description     MongoDB Database index size db_ttlsa_posts
      check_command           check_mongodb_database!10.1.11.155!27017!check_mongodb!www.ttlsa.com!database_indexes!50!100!db_ttlsa_posts
}
#15 Check index size of a collection 检查一个集合的索引大小

define service {
      use                     generic-service
      hostgroup_name          Mongo Servers
      service_description     MongoDB Database index size db_ttlsa_posts
      check_command           check_mongodb_collection!10.1.11.155!27017!check_mongodb!www.ttlsa.com!collection_indexes!50!100!db_ttlsa_posts!posts
}
#16 Check the primary server of replicaset 检查replicaset的主服务器
define service {
      use                     generic-service
      hostgroup_name          Mongo Servers
      service_description     MongoDB Replicaset Master Monitor: replset_ttlsa
      check_command           check_mongodb_replicaset!10.1.11.155!27017!check_mongodb!www.ttlsa.com!replica_primary!0!1!replset_ttlsa
}
#17 Check the number of queries per second 检查每秒查询数量。这将检查服务器上每秒查询数量,类型有:query|insert|update|delete|getmore|command

define service {
      use                     generic-service
      hostgroup_name          Mongo Servers
      service_description     MongoDB Updates per Second
      check_command           check_mongodb_query!10.1.11.155!27017!check_mongodb!www.ttlsa.com!queries_per_second!200!150!update
}
#18 Check Primary Connection
define service {
    use                 generic-service
    hostgroup_name          Mongo Servers
    service_description     Mongo Connect Check
    check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!connect_primary!2!4
}
#19 Check Collection State 检测集合状态
define service {
    use                 generic-service
    hostgroup_name          Mongo Servers
    service_description     Mongo Collection State
    check_command           check_mongodb!10.1.11.155!27017!check_mongodb!www.ttlsa.com!collection_state!db_ttlsa_posts!posts
}

vim /usr/local/nagios/etc/nagios.cfg #nagios 配置文件 
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg #新建 hosts.cfg 文件,存放主机与主机组定义 
cfg_file=/usr/local/nagios/etc/objects/services.cfg #新建 services.cfg 文件,存放服务与服务组定义 
 #检测无误后重启服务
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 
service nagios reload
posted @ 2017-06-10 09:50  xiaoganghu  阅读(546)  评论(0编辑  收藏  举报