Nagios监控数据库的方法

运维 系统运维
Nagios监控数据库的方法:Nagios是一个监控系统运行状态和网络信息的监控系统。Nagios能监控所指定的本地或远程主机以及服务,同时提供异常通知功能等。这篇文章讲述的是Nagios监控数据库的方法。

  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阀值(默认)

#p#

  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.   }  
  12.  

  ———————————————————–

#p#

  nagios-mysql-plugins插件监控数据库

  一、安装此插件

  1.   #wget 北北没有给地址  
  2.  
  3.   #tar zxvf nagios-mysql-plugins-0.3.tar.gz -C ../software/  
  4.  
  5.   #cd nagios-mysql-plugins-0.3  
  6.  
  7.   #chmod +x *mysql*  
  8.  

  二、插件内容

  check_db_mysql.pl 检测mysql是否运行

  check_errorlog_mysql.pl 检测mysql数据库错误日志

  check_repl_mysql_cnt_slave_hosts.pl 统计连接到从主机数

  check_repl_mysql_heartbeat.pl 检测心跳 (安装完默认名字是check_repl_mysql_hearbeat.pl)

  check_repl_mysql_io_thread.pl 检测IO线程

  check_repl_mysql_read_exec_pos.pl

  check_repl_mysql_readonly.pl 检测从是否设置为只读

  check_repl_mysql_seconds_behind_master.pl检测从多少时间与主同步

  check_repl_mysql_sql_thread.pl 检测SQL线程

  perf_mysql.pl 收集性能数据

  1.   perf_mysql.pl -m  
  2.  
  3.   connections,  
  4.  
  5.   thread_cache,  
  6.  
  7.   network_traffic,  
  8.  
  9.   queries,query_cache,  
  10.  
  11.   myisam_key_buffer,  
  12.  
  13.   table_cache,  
  14.  
  15.   temporary_tables,  
  16.  
  17.   tables,  
  18.  
  19.   slow_queries,  
  20.  
  21.   bin_log,uptime,  
  22.  
  23.   innodb_buffer_pool,  
  24.  
  25.   innodb_buffer_pool_io,  
  26.  
  27.   innodb_io,innodb_data,  
  28.  
  29.   innodb_logfile,  
  30.  
  31.   innodb_row_locking,  
  32.  
  33.   innodb_queries  

【编辑推荐】

Nagios飞信Linux系统免费短信报警配置

20分钟内在Ubuntu上实现Nagios的主机监控

Nagios监控oracle

责任编辑:zhaolei 来源: nagiostutorial
相关推荐

2011-03-24 10:59:09

Nagios监控Mysql

2011-03-21 13:10:13

NagiosWindows

2011-03-04 10:47:06

Nagios监控Sphinx

2011-03-24 10:08:39

Nagios监控oracle

2011-03-28 17:18:57

nagios监控iostat

2014-04-09 11:43:54

Zabbix监控Mysql数据库

2011-03-21 14:53:27

Nagios监控Linux

2011-08-24 13:49:45

Access数据库转化

2011-04-01 15:42:13

CactiNagios

2010-10-26 15:54:02

连接oracle数据库

2010-10-26 11:04:48

oracle数据导入

2011-03-22 09:07:12

nagios监控oracle

2012-02-22 22:21:15

nagios开源

2011-03-21 14:43:42

2011-03-22 13:00:49

Nagios监控

2011-03-21 13:10:15

Nagios监控

2011-03-23 10:17:24

2010-06-03 17:12:30

Windows Ser

2011-03-21 14:53:27

Nagios监控Linux

2011-04-06 14:24:21

Nagios监控Linux
点赞
收藏

51CTO技术栈公众号