標籤:thread nes master user query 串連 and soc uptime
安裝mysql之後,需要對mysql服務進行監控。
nagios開源內建的check_mysql 對 mysql 的slave 機監控倒是不錯。但是對資料庫主機監控就略顯不足了。 使用一個監控外掛程式:check_mysql_health 下載和使用方法見: http://exchange.nagios.org/directory/MySQL/check_mysql_health/details 具體監控: 對於slave 機 ,使用nagios 內建的 check_mysql 監控 command[check_mysql_slave]=/usr/local/nagios/libexec/check_mysql -H localhost -s /tmp/mysql.sock -u root -p xxx -S -w 1 -c 3 其中使用者和密碼有可能會更改。延遲1秒警告,延遲3秒警示。 check_mysql_health 監控mysql master 伺服器 /usr/local/nagios/libexec/custom/check_mysql_health --hostname localhost --socket /tmp/mysql.sock --username root --password xxxxxx --mode xxxxx --warning xxxxx --criticalxxxxx mode:
connection-time (Time to connect to the server)
uptime (Time the server is running)
threads-connected (Number of currently open connections)
threadcache-hitrate (線程快取命中率)
slave-lag (Seconds behind master)
slave-io-running (Slave io running: Yes)
slave-sql-running (Slave sql running: Yes)
qcache-hitrate (查詢命中率,如果這個值接近100%,說明伺服器select的最佳化就越好)
qcache-lowmem-prunes (因為記憶體小,從記憶體刪除緩衝查詢的數量,可以增大query_cache_size,減小lowmem,增加命中率的最佳化)
keycache-hitrate (MyISAM key 快取命中率,如果命中率太低,增大key_buffer_size)
bufferpool-hitrate (InnoDB 緩衝池命中率)
bufferpool-wait-free (InnoDB 緩衝池等待清理的頁面)
log-waits (InnoDB log 等待寫入時間,如果這個等待時間太大,增大log緩衝池大小)
tablecache-hitrate (Table 快取命中率)
table-lock-contention (Table 的lock率)
index-usage (索引使用率,越大說明索引越好,越小說明索引最佳化不充分)
tmp-disk-tables (暫存資料表建立的數量)
slow-queries (慢查詢占所有查詢的比率,這個值如果很高說明mysql資料庫最佳化不夠)
long-running-procs (長期啟動並執行進程)
cluster-ndbd-running (mysql叢集監控)
sql (執行一個返回一個數位SQL,檢查mysql是否可以連結查詢)
舉例:nrpe.cfg:command[check_mysql_health]=/usr/local/nagios/libexec/custom/check_mysql_health --hostname localhost --socket /tmp/mysql.sock --username xxxxx --password xxxxx --mode $ARG1$ --warning $ARG2$ --critical $ARG3$ xxx.cfg:define service{ use xxxxxx host_name xxxxxx service_description mysql資料庫連接數 check_command check_nrpe_args!check_mysql_health!threads-connected!80!120} define service{ use xxxxx host_name xxxxx service_description mysql資料庫innodb快取命中 check_command check_nrpe_args!check_mysql_health!bufferpool-hitrate}define service{ use xxxxx host_name xxxxx service_description mysql資料庫innodb緩衝池等待清理的頁 check_command check_nrpe_args!check_mysql_health!bufferpool-wait-free}define service{ use xxxxx host_name xxxxx service_description mysql資料庫innodblog寫入等待時間 check_command check_nrpe_args!check_mysql_health!log-waits}define service{ use xxxxx host_name xxxxx service_description mysql資料庫鎖表率 check_command check_nrpe_args!check_mysql_health!table-lock-contention}define service{ use xxxxx host_name xxxxx service_description mysql資料庫開啟檔案數 check_command check_nrpe_args!check_mysql_health!open-files!80!90}define service{ use xxxxx host_name xxxxx service_description mysql資料庫慢查詢率 check_command check_nrpe_args!check_mysql_health!slow-queries!5!10} 搞定。 PS:對 warnging 和 critical 的值 : 10 就是 大於10%警示, 10: 就是小於10%警示, 不填就是預設的數值。mode 一個語句只能一個, --mode xxx1 xxx2 : xxx1 生效--mode xxx1 --mode xxx2 : xxx2 生效
監控mysql各種選項