zoukankan      html  css  js  c++  java
  • MySQL监控

    check_mysql_health插件比起Nagios官方的check_mysql插件功能更为强大

    check_mysql_health不但能监控MySQL是否正常运行,还能监控MySQL主从、MySQL连接数情况、MySQL慢查询等多种监控指标。

    1)安装check_mysql_health

    apt-get install libdbd-mysql-perl libdbi-perl

    tar xvzf DBI-1.618.tar.gz
    cd DBI-1.618
    perl Makefile.PL
    make && make install

    tar xvzf check_mysql_health-2.1.7tar.gz cd check_mysql_health-2.1.7 ./configure --prefix=/usr/local/nagios/ --with-nagios-user=nagios --with-nagios-group=nagios -with-mymodules-dir=/usr/local/nagios/libexec --with-mymodules-dyn-dir=/usr/local/nagios/libexec make make install

    2)部署Nagios上的 check_mysql_health

    创建mysql用户

    root连接到服务器上后,添加新帐户。下面的语句使用GRANT来设置4个新帐户:

    mysql>GRANT ALL PRIVILEGES 0N *.* TO ‘monty’@ ‘localhost’ IDENTIFIED BY ‘some_pass’ WITH GRANT OPTION;
    mysql>GRANT ALL PRIVILEGES 0N *.* TO ‘monty’@ ‘%’ IDENTIFIED BY ‘some_pass’ WITH GRANT OPTION;
    mysql>GRANT RELOAD,PROCESS ON *.* TO ‘admin’@ ‘localhost’;
    mysql>GRANT USAGE ON *.* TO ‘dummy’@ ‘localhost’;

    GRANT语句创建 的帐户有下面的属性:

    其中两个帐户有相同的用户名monty和密码some_pass,两个帐户均为超级用户帐户,具有完全的权限可以做任何事情,一个帐户(’monty’@’localhost’)只用于从本机连接时,另一个帐户(’monty’@’%’)可用于从其它主机连接。请注意monty的两个帐户必须能从任何主机以monty连接。没有localhost 帐户,当monty 从本机连接时,mysql_install_db创建的localhost的匿名用户帐户将占先。结果是,monty将被视为匿名用户。原因是匿名用户帐户的Hosting列值比’monty’@’%’帐户更具,这样在user表排序顺序中排在前面。(user表排序的计论在参考mysql手册)。

    一个帐户有用户名admin,没有密码。该帐户只用于从本机连接。授予了RELOADPROCESS管理权限。这些权限允许admin 用户执行mysqladmin reloadmysqladmin refreshmysqladmin flush-xxx命令,以及mysqladmin processlist。未授予访问数据库的权限。可以通过GRANT语句添加此类权限。

    3)check_mysql_health插件基本用法

    check_mysql_health --hostname localhost --port 3306 --username root --password 123456 --mode threads-connected

    返回:

    OK - 1 client connection threads | threads_connected=1;10;20

    各参数具体含义

    --hostname  定义被监控主机的IP或机器名 
    --port    定义被监控主机上MySQL的运行端口
    --username
      定义被监控主机上MySQL的用户名
    --password
      定义被监控主机上MySQL的密码
    --mode
        定义被监控主机上MySQL的监控指标
    #监控MySQL主从
    #mysql -u root -p
    # mysql>GRANT ALL ON *.* TO root@10.0.1.180 IDENTIFIED BY '123456';
    # mysql>Flush Privileges;
    # mysql>exit;

    4)配置commands.cfg

    vi /usr/local/icinga/etc/objects/commands.cfg
    define command{

      command_name check_mysql_health
      command_line $USER1$/check_mysql_health --hostname $HOSTADDRESS$ --port $ARG1$ --username $ARG2$ --password $ARG3$ --mode $ARG4$
    }

    5)配localhost.cfg

    --mode
    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)
    threads-created      	(Number of threads created per sec)
    threads-running      	(Number of currently running threads)
    threads-cached       	(Number of currently cached threads)
    connects-aborted     	(Number of aborted connections per sec)
    clients-aborted      	(Number of aborted connections (because the client died) per sec)
    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)
    table-fragmentation  	(Show tables which should be optimized)
    open-files           	(Percent of opened files)
    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)
    
    #connection-time##########
    define service{   use          local-service   host_name       localhost   service_description mysql_connection_time   check_command check_mysql_health!localhost!3306!root!123456!connection-time }
    
    
    
  • 相关阅读:
    Python 面向对象4-特殊成员
    Python 面向对象3-成员修饰符
    Python 面向对象2
    Python 面向对象
    Python hashlib模块
    使用Access-Control-Allow-Origin解决跨域
    倒计时
    移动端之touch事件--手指的滑动事件
    HTML5获取地理经纬度并通过百度接口得到实时位置
    h5直播
  • 原文地址:https://www.cnblogs.com/wowchky/p/3225465.html
Copyright © 2011-2022 走看看