【MySQL】数据库监控(Nagios)

[root@wallet03 ~]# yum install -y perl-DBI perl-DBD-MySQL

[root@wallet03 ~]# tar zxvf check_mysql_health-2.2.2.tar.gz 
[root@wallet03 ~]# cd check_mysql_health-2.2.2
[root@wallet03 check_mysql_health-2.2.2]# ./configure --prefix=/usr/local/nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios
[root@wallet03 check_mysql_health-2.2.2]# make
[root@wallet03 check_mysql_health-2.2.2]# make install

[root@wallet03 ~]# cd /usr/local/nagios/libexec/
[root@wallet03 libexec]# ./check_mysql_health 
Please select a mode

Copyright (c) 2009 Gerhard Lausser
  Check various parameters of MySQL databases 
  Usage:
    check_mysql_health [-v] [-t <timeout>] [[--hostname <hostname>] 
        [--port <port> | --socket <socket>]
        --username <username> --password <password>] --mode <mode>
        [--method mysql]
        
[root@wallet03 libexec]# ./check_mysql_health --hostname 192.168.1.202 --username nagios --password nagios --mode connection-time 
OK - 0.02 seconds to connect as nagios | connection_time=0.0169s;1;5

[root@wallet03 libexec]# ./check_mysql_health --hostname 192.168.1.202 --username nagios --password nagios --mode uptime
OK - database is up since 7542 minutes | uptime=452541s

[root@wallet03 ~]# cd /usr/local/nagios/etc/objects
[root@wallet03 objects]# vi commands.cfg
define command{
        command_name    check_mysql
        command_line    $USER1$/check_mysql_health --hostname $ARG1$ --username nagios --password nagios --mode $ARG2$
        }
        
[root@wallet03 objects]# vi mysql.cfg
define host{
        use                     linux-server
        host_name               wallet01
        alias                   wallet01
        icon_image              redhat.gif
        statusmap_image         redhat.gd2
        address                 192.168.1.202
        }
        
define hostgroup{
        hostgroup_name  database
        alias           database  
        members         wallet02
        }
                
define service{
        host_name                       wallet02
        use                             generic-service
        service_description             mysql connection time
        check_command                   check_mysql!192.168.1.202!connection-time
        }
        
define service{
        host_name                       wallet02
        use                             generic-service
        service_description             mysql uptime
        check_command                   check_mysql!192.168.1.202!uptime
        }
        
define service{
        host_name                       wallet02
        use                             generic-service
        service_description             mysql client-connected
        check_command                   check_mysql!192.168.1.202!threads-connected
        }
        
define service{
        host_name                       wallet02
        use                             generic-service
        service_description             mysql slow-queries
        check_command                   check_mysql!192.168.1.202!slow-queries
        }
        
define service{
        host_name                       wallet02
        use                             generic-service
        service_description             mysql tmp-disk-tables
        check_command                   check_mysql!192.168.1.202!tmp-disk-tables
        }
        
define service{
        host_name                       wallet02
        use                             generic-service
        service_description             mysql slave-lag
        check_command                   check_mysql!192.168.1.202!slave-lag
        }
        
define service{
        host_name                       wallet02
        use                             generic-service
        service_description             mysql slave-io-running
        check_command                   check_mysql!192.168.1.202!slave-io-running
        }
        
define service{
        host_name                       wallet02
        use                             generic-service
        service_description             mysql slave-sql-running
        check_command                   check_mysql!192.168.1.202!slave-sql-running
        }
        
[root@wallet03 ~]# cd /usr/local/nagios/etc        
[root@wallet03 etc]# vi icinga.cfg 
cfg_file=/usr/local/nagios/etc/objects/mysql.cfg 
               
[root@wallet03 ~]# service icinga restart
Running configuration check...OK
Stopping Icinga: Waiting for icinga to exit ..Stopping icinga done.
Starting icinga: Starting icinga done.
上一篇:Prometheus简介


下一篇:在ubuntu上安装nagios