Nagios监控数据库的方法

来源:互联网 发布:java同时定义多个变量 编辑:程序博客网 时间:2024/05/22 10:23

Nagios监控数据库的方法:

check_mysql_health监控数据库

1、check_mysql_health安装

在监控服务器上安装

  1. # cd /usr/local/src/tarbag  
  2.  
  3. # wget http://labs.consol.de/wp-content/uploads/2010/03/check_mysql_health-2.1.1.tar.gz  
  4.  
  5. # tar zxvf check_mysql_health-2.1.1.tar.gz -C ../software/  
  6.  
  7. # ./configure \  
  8.  
  9. prefix=/usr/local/nagios/ \  
  10.  
  11. with-nagios-user=nagios \  
  12.  
  13. with-nagios-group=nagios \  
  14.  
  15. with-perl=/usr/bin/perl \  
  16.  
  17. with-statefiles-dir=/usr/local/nagios/var/tmp \  
  18.  
  19. –with-perl perl\ 程序运行路径  
  20.  
  21. –with-statefiles-dir 状态信息文件路径  
  22.  
  23. # make  
  24.  
  25. # make install  
  26.  

2、check_mysql_health选项

  1. Options:  
  2.  
  3. –hostname  
  4.  
  5. the database server’s hostname  
  6.  
  7. –port  
  8.  
  9. the database’s port. (default: 3306)  
  10.  
  11. –socket  
  12.  
  13. the database’s unix socket.  
  14.  
  15. –username  
  16.  
  17. the mysql db user  
  18.  
  19. –password  
  20.  
  21. the mysql db user’s password  
  22.  
  23. –database  
  24.  
  25. the database’s name. (default: information_schema)  
  26.  
  27. –warning  
  28.  
  29. the warning range  
  30.  
  31. –critical  
  32.  
  33. the critical range  
  34.  
  35. –mode  
  36.  
  37. the mode of the plugin. select one of the following keywords:  
  38.  
  39. connection-time 连接到服务器上的时间  
  40.  
  41. uptime 服务器运行的时间  
  42.  
  43. threads-connected 当前连接到数据库的连接数  
  44.  
  45. threadcache-hitrate 线程缓存命中率  
  46.  
  47. slave-lag slave落后master多少时间  
  48.  
  49. slave-io-running slave复制是否正常  
  50.  
  51. slave-sql-running slave复制是否正常  
  52.  
  53. qcache-hitrate 查询缓存命中率  
  54.  
  55. qcache-lowmem-prunes (Query cache entries pruned because of low memory)  
  56.  
  57. keycache-hitrate (MyISAM key cache hitrate)  
  58.  
  59. bufferpool-hitrate (InnoDB buffer pool hitrate)  
  60.  
  61. bufferpool-wait-free (InnoDB buffer pool waits for clean page available)  
  62.  
  63. log-waits (InnoDB log waits because of a too small log buffer)  
  64.  
  65. tablecache-hitrate 表缓存命中率  
  66.  
  67. table-lock-contention 表锁率  
  68.  
  69. index-usage 索引使用情况  
  70.  
  71. tmp-disk-tables (Percent of temp tables created on disk)  
  72.  
  73. slow-queries 慢查询  
  74.  
  75. long-running-procs 长时间运行的进程  
  76.  
  77. cluster-ndbd-running ndb节点运行状况  
  78.  
  79. sql 返回一个数字的任何SQL语句  
  80.  

3、check_mysql_health监控配置

监控服务器:10.59.97.42

MySQL数据授权:

在要监控的MySQL数据库服务器上

  1. mysql> grant usage on *.* to honyho@10.59.97.42 identified by “honyho@8123“;  
  2.  
  3. mysql> flush privileges;  
  4.  

在监控服务器上

1》查看当前连接到数据库的连接数

  1. #./check_mysql_health –hostname 10.59.97.57 –username honyho –password honyho@8123 –mode threads-connected  
  2.  
  3. OK – 3 client connection threads | threads_connected=3;10;20  
  4.  
  5. threads_connected=3;10;20  
  6.  

3表示连接数

10 表示warning阀值(默认)

20 表示critical阀值(默认)

Nagios相关配置

1》配置commands.cfg文件

  1. define command{  
  2.  
  3. command_name check_mysql_health  
  4.  
  5. command_line $USER1$/check_mysql_health –hostname $ARG1$ –username $ARG2$ –password $ARG3$ –warning $ARG4$ –critical $ARG5$ –mode $ARG6$  
  6.  
  7. }  
  8.  

2》配置121_207_231_17.cfg文件

  1. define service{  
  2.  
  3. use local-service  
  4.  
  5. host_name 121.207.231.17  
  6.  
  7. service_description threads-connected  
  8.  
  9. check_command check_mysql_health!10.59.97.57!honyho!honyho@8123!1000!1500!threads-connected  
  10.  
  11. }  
0 0
原创粉丝点击