數據庫MySQL的監控

對什麼進行監控

A、監控數據庫MySQL的可用性

數據庫進程或是端口存在,並不意味着數據庫是可用的。通過網絡連接到數據庫並且確定數據庫是對外提供服務的。

B、對數據庫性能進行監控

QPS和TPS,MySQL併發線程數量,如何對Innodb阻塞和死鎖進行監控。

C、對主從複製進行監控

D、對服務器資源的監控

磁盤空間,服務器磁盤空間大並不意味着MySQL數據庫服務能使用的空間就足夠大。

CPU的使用情況,內存的使用情況,Swap分區的使用情況以及網路IO的情況等。

一、數據庫可用性監控

1、如何確認數據庫是否可以通過網絡連接,MySQL本地的SQL文件連接到數據庫服務器,並不意味着能通過網絡TCP/IP協議能連接到MySQL。

mysqladmin -umonitor_user -p -h ping

telnet ip db_port

使用程序通過網絡建立數據庫連接

2、如何確認數據庫是否可讀寫

檢查數據庫的read_ony參數是否爲off

建立監控表對錶中數據進行更新

執行簡單的查詢select @@version;

3、如何監控數據庫的連接數

show variables like 'max_connections';

show global status like 'Threads_connected';

根據Threads_connected / max_connections的值判斷是否需要向管理員報警。

4、數據庫性能監控

記錄性能監控過程中所採集到的數據庫的狀態

如何計算QPS和TPS

QPS=(Queries2-Queries1)/(Uptime_since_flush_status2-Uptime_since_flush_status1)

TPS=((Com_insert2+Com_update2+Com_delete2)-(Com_insert1+Com_update1+Com_delete1))/(Uptime_since_flush_status2-Uptime_since_flush_status1)

如何監控數據庫的併發請求數量,數據庫性能的性能會隨着併發處理請求數量的增加而下降。

CPU使用率

show global status like 'Threads_running';

併發處理的數量通常會遠小於同一時間連接到數據庫的線程的數量。

數據庫出現大量阻塞。

如何監控Innodb的阻塞

select b.trx_mysql_thread_id as '被阻塞線程'

,b.trx_query as '被阻塞SQL'

,c.trx_mysql_thread_id as '阻塞線程'

,c.trx_query as '阻塞SQL'

,(unix_timestamp()-unix_timestamp(c.trx_started)) as '阻塞時間'

from information_schema.innodb_lock_waits as

join information_schema.innodb_trx b on a.requestion_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

顯示連接ID

select connection_id();

設置鎖的超時時間

set global innodb_lock_wait_timeout=180;

5、如何監控主從複製鏈路的狀態

如何監控主從複製延遲

show slave status \G

show master status \G

如何驗證主從複製的數據是否一致

 pt-table-checksum u=dba,p='PassWord'\

--databases mysql \

--replicate test.checksums


grant select,process,super,replication salve on *.* to 'dba'@'ip' identified by 'PassWord'


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