Nagios監控數據庫的方法
Nagios監控數據庫的方法:
check_mysql_health監控數據庫
1、check_mysql_health安裝
在監控服務器上安裝
- # cd /usr/local/src/tarbag
- # wget http://labs.consol.de/wp-content/uploads/2010/03/check_mysql_health-2.1.1.tar.gz
- # tar zxvf check_mysql_health-2.1.1.tar.gz -C ../software/
- # ./configure \
- –prefix=/usr/local/nagios/ \
- –with-nagios-user=nagios \
- –with-nagios-group=nagios \
- –with-perl=/usr/bin/perl \
- –with-statefiles-dir=/usr/local/nagios/var/tmp \
- –with-perl perl\ 程序運行路徑
- –with-statefiles-dir 狀態信息文件路徑
- # make
- # make install
2、check_mysql_health選項
- Options:
- –hostname
- the database server’s hostname
- –port
- the database’s port. (default: 3306)
- –socket
- the database’s unix socket.
- –username
- the mysql db user
- –password
- the mysql db user’s password
- –database
- the database’s name. (default: information_schema)
- –warning
- the warning range
- –critical
- the critical range
- –mode
- the mode of the plugin. select one of the following keywords:
- connection-time 連接到服務器上的時間
- uptime 服務器運行的時間
- threads-connected 當前連接到數據庫的連接數
- threadcache-hitrate 線程緩存命中率
- slave-lag slave落后master多少時間
- slave-io-running slave復制是否正常
- slave-sql-running slave復制是否正常
- qcache-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-lock-contention 表鎖率
- index-usage 索引使用情況
- tmp-disk-tables (Percent of temp tables created on disk)
- slow-queries 慢查詢
- long-running-procs 長時間運行的進程
- cluster-ndbd-running ndb節點運行狀況
- sql 返回一個數字的任何SQL語句
3、check_mysql_health監控配置
監控服務器:10.59.97.42
MySQL數據授權:
在要監控的MySQL數據庫服務器上
- mysql> grant usage on *.* to honyho@10.59.97.42 identified by “honyho@8123“;
- mysql> flush privileges;
在監控服務器上
1》查看當前連接到數據庫的連接數
- #./check_mysql_health –hostname 10.59.97.57 –username honyho –password honyho@8123 –mode threads-connected
- OK – 3 client connection threads | threads_connected=3;10;20
- threads_connected=3;10;20
3表示連接數
10 表示warning閥值(默認)
20 表示critical閥值(默認)
#p#
Nagios相關配置
1》配置commands.cfg文件
- define command{
- command_name check_mysql_health
- command_line $USER1$/check_mysql_health –hostname $ARG1$ –username $ARG2$ –password $ARG3$ –warning $ARG4$ –critical $ARG5$ –mode $ARG6$
- }
2》配置121_207_231_17.cfg文件
- define service{
- use local-service
- host_name 121.207.231.17
- service_description threads-connected
- check_command check_mysql_health!10.59.97.57!honyho!honyho@8123!1000!1500!threads-connected
- }
———————————————————–
#p#
nagios-mysql-plugins插件監控數據庫
一、安裝此插件
- #wget 北北沒有給地址
- #tar zxvf nagios-mysql-plugins-0.3.tar.gz -C ../software/
- #cd nagios-mysql-plugins-0.3
- #chmod +x *mysql*
二、插件內容
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 收集性能數據
- perf_mysql.pl -m
- connections,
- thread_cache,
- network_traffic,
- queries,query_cache,
- myisam_key_buffer,
- table_cache,
- temporary_tables,
- tables,
- slow_queries,
- bin_log,uptime,
- innodb_buffer_pool,
- innodb_buffer_pool_io,
- innodb_io,innodb_data,
- innodb_logfile,
- innodb_row_locking,
- innodb_queries
【編輯推薦】