• nagios监控mysql


    本监控为基于nagios服务器主动监控方法,利用check_mysql_health实现多种监控模式:
           connection-time          (Time to connect to the server)
           uptime                   (Time the server is running)
           threads-connected        (Number of currently open connections)线程数
           threadcache-hitrate      (Hit rate of the thread-cache)慢查询
           slave-lag                (Seconds behind master)
           slave-io-running         (Slave io running: Yes)主从热备
           slave-sql-running        (Slave sql running: Yes)主从热备
           qcache-hitrate           (Query cache hitrate)
           qcache-lowmem-prunes     (Query cache entries pruned because of low memory)
           keycache-hitrate         (MyISAM key cache hitrate)
           bufferpool-hitrate       (InnoDB buffer pool hitrate)
           bufferpool-wait-free     (InnoDB buffer pool waits for clean 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          (Percent of 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't locate 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 und den Performancedaten. 
    –warning <range> 
    –critical <range> 
    –environment <variable>=<wert> 
    –method <connectmethode> 
    Mit diesem Parameter teilt man dem Plugin mit, wie es sich zur Datenbank verbinden 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$
            }
    ...

    #vi /usr/local/nagios/etc/objects/servers/localhost.cfg
    ...

    define service{
            use                             local-service         ; Name of service template 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 service template 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

  • 相关阅读:
    find命令进阶(二):对找到的文件执行操作exec
    find命令进阶用法(一)
    find按照文件大小查找
    find命令查找目录
    什么是ppa
    Linux进程管理命令
    [HDOJ4135]Co-prime
    [HDOJ5391]Zball in Tina Town
    [模拟]位运算实现四则运算
    [HDOJ1233]还是畅通工程
  • 原文地址:https://www.cnblogs.com/zhming26/p/5462760.html
Copyright © 2020-2023  润新知