MySQL常用監控項
- 2019 年 12 月 13 日
- 筆記
1
資料庫版本
mysqladmin version
2
需要監控的基本狀態資訊
資料庫的連接狀態
mysqladmin ping
資料庫啟動時間
Uptime
資料庫當前連接數
Threads_connected
資料庫使用的連接最大個數
max_used_connections
資料庫放棄的連接個數
aborted_clients
資料庫嘗試連接失敗次數
aborted_connects
資料庫軟體目錄
資料庫數據目錄
3
需要監控的參數
Server_Id
(主從不能相同)
Read_Only
(只讀是否開啟)
Max_Connections
(最大允許同時連接的數量)
Max_Connect_Errors
(允許一個主機最多的錯誤鏈接次數)
Wait_Timeout
(指的是mysql在關閉一個非交互的連接之前所要等待的秒數)
Skip_Name_Resolve
(禁用DNS主機名查找)
Sync_Binlog
(雙一)
Innodb_Flush_Log_At_Trx_Commit
(雙一)
Expire_Logs_Days
(Binlog保留的天數)
Table_Open_Cache
(所有執行緒打開表的數量)
Query_Cache_Size
(查詢快取大小)
Sort_Buffer_Size
(會話的排序空間)
Read_Buffer_Size
(MySQL讀入緩衝區大小)
Join_Buffer_Size
(為鏈接操作分配的最小快取大小)
Tmp_Table_Size
(臨時表的大小)
open_files_limit
(作業系統允許mysql打開的文件數量)
Lower_Case_Table_Names
(大小寫敏感)
Innodb_Buffer_Pool_Size
(innodb緩衝池大小)
Innodb_Thread_Concurrency
(並發執行緒數量)
Innodb_Flush_Method
(innodb數據文件及redo log的打開、刷寫模式)
Innodb_File_Per_Table
(InnoDB為獨立表空間模式)
Innodb_Lock_Wait_Timeout
(事務等待獲取資源等待的最長時間)
Innodb_Open_Files
(限制Innodb能打開的表的數據)
Log_Bin
(二進位日誌開關)
Log_Bin_Basename
(二進位日誌文件名)
Log_Bin_Index
(二進位日誌索引文件名)
Binlog_Format
(二進位日誌的格式)
Binlog_Row_Image
(minimal只記錄要修改的列的記錄)
Log_Timestamps
(記錄日誌的顯示時間參數,設置成SYSTEM)
Slow_Query_Log
(慢日誌是否開啟)
Slow_Query_Log_File
(慢日誌存放位置)
Log_Error
(錯誤日誌存放位置)
4
資料庫主從狀態監控項
Master/ Slave
判斷是主庫還是從庫
SlaveIO Running
IO進程運行狀態
SlaveSQL Running
SQL進程運行狀態
MasterLog File
主庫二進位日誌文件
RelayMaster Log File
是否跟得上Master Log File
ReadMaster Log Pos
讀到主庫上的POS值
ExecMaster Log Pos
執行主庫上的POS值
SecondsBehind Master
從庫和主庫的延遲時間
5
資料庫其它監控項
資料庫中的大表
selecttable_schema,table_name,round((sum(DATA_LENGTH)+sum(INDEX_LENGTH))/1024/1024,2)"Size(M)" from information_schema.tables group by table_schema,table_nameorder by round((sum(DATA_LENGTH)+sum(INDEX_LENGTH))/1024/1024,2) desc limit10G'
資料庫未建主鍵索引的表
SELECTdistinct table_name,table_schema FROM information_schema.columns WHEREtable_schema not in ('sys','information_schema','performance_schema','mysql')AND table_name not in (select distinct table_name frominformation_schema.columns where column_key='PRI')G"
資料庫鎖統計
showstatus like 'table_locks_%'G"
資料庫快取命中率
如果Qcache_hits+Com_select<>0則為 Qcache_hits/(Qcache_hits+Com_select),否則為0
執行緒快取命中率
如果Connections<>0,則為1-Threads_created/Connections,否則為0
創建磁碟存儲的臨時表比率
如果Created_tmp_disk_tables+Created_tmp_tables<>0,則Created_tmp_disk_tables/(Created_tmp_disk_tables+Created_tmp_tables),否則為0
連接使用率
如果max_connections<>0,則threads_connected/max_connections,否則為0
打開文件比率
如果open_files_limit<>0,則open_files/open_files_limit,否則為0,錶快取使用率如果table_open_cache<>0,則open_tables/table_open_cache,否則為0
資料庫Innodb中Read命中率
showstatus like 'Innodb_buffer_pool_%'G"
資料庫全表掃描情況
showglobal status like 'handler_read%'G"