數據庫可用行與性能監控

可用行:

1.監控數據庫是否可以連接

  方法:

      mysqladmin -umonitor_user -p -h ping

     telnet ip db_port

2.監控數據庫是否可以讀寫

   方法:

      檢查數據庫read_only參數是否爲off.

      建立監控表對錶中數據進行操作

     連接後可以執行 select @@version

3.監控數據庫的連接數

  方法:

      show variables like 'max_connections'

     show global status like 'Threads_connected'

    Threads_connected / max_connections>0.8 就需要報警

性能監控:

1.監控數據庫併發請求數量

   show global status like 'Thread_running'

  如何監控Innodb的阻塞:

   從mysql性能字典表,innodb_lock_waits 是鎖信息,innodb_trx是事務信息,有兩條記錄,需要放到一行中,因此,需要關聯2次。 

select b.trx_mysql_thread_id as ‘被阻塞線程’, 
b.trx_query as ‘被阻塞SQL’, 
b.trx_mysql_thread_id as ‘阻塞線程’, 
b.trx_query as ‘阻塞SQL’, 
(UNIX_TIMESTAMP() - UNIX_TIMESTAMP(b.trx_started)) as ‘阻塞時間’ 
from 
information_schema.innodb_lock_waits a 
join information_schema.innodb_trx b 
on a.requesting_trx_id=b.trx_id 
join information_schema.innodb_trx c 
on a.blocking_trx_id=c.trx_id 
where (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(c.trx_started))>60; 

設置全局鎖的超時時間:
 set global innodb_lock_wait_timeout=180;

查看線程相互阻塞的方法: 

show engine innodb status \G 查看詳細事務內容 
SELECT b.,a. FROM information_schema.INNODB_TRX a,information_schema.PROCESSLIST b WHERE a.trx_mysql_thread_id=b.ID AND a.trx_state=’RUNNING’ ; 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章