啓動innodb_monitor的方法

http://g.51cto.com/mike/67136


在使用Innodb做爲存儲引擎的數據庫系統中,可以使用innodb_monitor 來監控數據庫的性能,啓動innodb_monitor的方法爲 Create table innodb_monitor (i int) engine=innodb 通過建立這個表就啓動了innodb_monitor,監控的結果並不會記錄到這個表中,而是記錄到了mysql的err日誌中,如果我們想監控更我的關於innodb的鎖信息還可更進一步的建立表create table innodb_lock_monitor (i int) engine=innodb 這樣在日誌中會加入更多的鎖信息,如果要關閉監控只要簡單的刪除這兩個表就可以了.Drop table innodb_monitor; drop table innodb_lock_monitor;

用InnoDB monitor 可以監控死鎖的情況等用InnoDB monitor 可以監控死鎖的情況等
InnoDB引擎提供了一個monitor,可以通過monitor一窺其內部的一些統計信息,也可以說是瞭解InnoDB引擎的一個很好的窗口。
我們最熟悉的,應當就是show innodb status命令,可以直接在客戶端輸出很多的信息。其實InnoDB monitor一共有四種模式,show innodb status只是其一種模式的直接展現,並且只能交互式開啓,無法自動循環捕獲信息。另外還有一種適合四種模式的開啓方式,則是通過創建一張特殊的innodb表來開啓,開啓後會按照固定的時間間隔循環,輸出信息到log-error參數指定的錯誤日誌文件中,通過drop對應的表,可以停止monitor。
四種monitor分別是:
  • innodb_monitor:create table innodb_monitor(x int) engine=innodb;

  • innodb_lock_monitor:create table innodb_lock_monitor(x int) engine=innodb;

  • innodb_table_monitor:create table innodb_table_monitor(x int) engine=innodb;

  • innodb_tablespace_monitor:create table innodb_tablespace_monitor(x int) engine=innodb;

根據我在5.1.36版本中實際觀察到的結果,innodb_monitor/innodb_lock_monitor開啓後的執行週期是16s參考手冊上說是15s),而innodb_table_monitor/innodb_tablespace_monitor的執行週期是64s。開啓monitor後因爲是持續週期性的運行的,在不需要的時候一定要記得drop相關表來停止monitor。如果在開啓monitor的中間服務器有重啓,monitor不會自動重啓,並且在下次啓動monitor之前,必須先執行停止操作。
其中innodb_monitor/innodb_lock_monitor兩種監視器的輸出結果基本類似,後者會有更多關於鎖的信息,而前一個實際上就是show innodb status。innodb_table_monitor則會將系統中所有innodb的表的一些結構和內部信息輸出,而innodb_tablespace_monitor則輸出的是tablespace的信息,注意該monitor輸出的只是共享表空間的信息,如果使用innodb_file_per_table爲每個表使用獨立的表空間,則這些表空間的信息是不會包含在輸出中的。
以下是一些簡單的示例:
innodb_monitor/innodb_lock_monitor:
=====================================
090805 22:24:48 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 19 seconds
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 312921, signal count 308229
Mutex spin waits 0, rounds 18209349, OS waits 111906
RW-shared spins 287775, OS waits 142204; RW-excl spins 175036, OS waits 19318
------------
TRANSACTIONS
------------
Trx id counter 0 121675664
Purge done for trx's n:o < 0 121675662 undo n:o < 0 0
History list length 10
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0 121462143, not started, process no 8452, OS thread id 1160767840
mysql tables in use 1, locked 1
MySQL thread id 8056144, query id 78206864 localhost root
---TRANSACTION 0 137229, not started, process no 8452, OS thread id 1158199648
MySQL thread id 50, query id 377 Has read all relay log; waiting for the slave I/O thread to update it
--------
FILE I/O
--------
I/O thread 0 state: waiting for i/o request (insert buffer thread)
I/O thread 1 state: waiting for i/o request (log thread)
I/O thread 2 state: waiting for i/o request (read thread)
I/O thread 3 state: waiting for i/o request (write thread)
Pending normal aio reads: 0, aio writes: 0,
 ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
34 OS file reads, 80820900 OS file writes, 1263117 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 1.16 writes/s, 0.63 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2,
0 inserts, 0 merged recs, 0 merges
Hash table size 8850487, node heap has 233 buffer(s)
0.11 hash searches/s, 0.42 non-hash searches/s
---
LOG
---
Log sequence number 4 3697502095
Log flushed up to   4 3697502095
Last checkpoint at  4 3697502095
0 pending log writes, 0 pending chkp writes
79595438 log i/o's done, 0.47 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 4851752298; in additional pool allocated 13195520
Dictionary memory allocated 145784
Buffer pool size   262144
Free buffers       193334
Database pages     68577
Modified db pages  0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages read 70, created 120513, written 2829967
0.00 reads/s, 0.21 creates/s, 0.84 writes/s
Buffer pool hit rate 1000 / 1000
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread process no. 8452, id 1157658976, state: waiting for server activity
Number of rows inserted 12233742, updated 57497659, deleted 1, read 69720050
0.05 inserts/s, 0.05 updates/s, 0.00 deletes/s, 0.05 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
innodb_table_monitor:
===========================================
090805 22:26:56 INNODB TABLE MONITOR OUTPUT
===========================================
--------------------------------------
TABLE: name SYS_FOREIGN, id 0 11, columns 7, indexes 3, appr.rows 0
  COLUMNS: ID: DATA_VARCHAR prtype 1835012 len 0; FOR_NAME: DATA_VARCHAR prtype 1835012 len 0;REF_NAME: DATA_VARCHAR prtype 1835012 len 0; N_COLS: DATA_INT len 4;DB_ROW_ID: DATA_SYS prtype 256 len 6; DB_TRX_ID: DATA_SYS prtype 257 len 6; DB_ROLL_PTR:DATA_SYS prtype 258 len 7;   INDEX: name ID_IND, id 0 11, fields 1/6, uniq 1, type 3   root page 46, appr.key vals 0, leaf pages 1, size pages 1   FIELDS:  ID DB_TRX_ID DB_ROLL_PTR FOR_NAME REF_NAME N_COLS  INDEX: name FOR_IND, id 0 12, fields 1/2, uniq 2, type 0   root page 47, appr.key vals 0, leaf pages 1, size pages 1   FIELDS:  FOR_NAME ID  INDEX: name REF_IND, id 0 13, fields 1/2, uniq 2, type 0   root page 48, appr.key vals 0, leaf pages 1, size pages 1   FIELDS:  REF_NAME ID...省略若干輸出--------------------------------------TABLE: name test/test, id 0 81, columns 4, indexes 1, appr.rows 3  COLUMNS: i: DATA_INT DATA_BINARY_TYPE len 4; DB_ROW_ID: DATA_SYS prtype 256 len 6;DB_TRX_ID: DATA_SYS prtype 257 len 6; DB_ROLL_PTR: DATA_SYS prtype 258 len 7;  INDEX: name GEN_CLUST_INDEX, id 0 23, fields 0/4, uniq 1, type 1   root page 3, appr.key vals 3, leaf pages 1, size pages 1   FIELDS:  DB_ROW_ID DB_TRX_ID DB_ROLL_PTR i-----------------------------------END OF INNODB TABLE MONITOR OUTPUT==================================
innodb_tablespace_monitor:
================================================
090805 22:28:16 INNODB TABLESPACE MONITOR OUTPUT
================================================
FILE SPACE INFO: id 0
size 65536, free limit 6208, free extents 89
not full frag extents 6: used pages 69, full frag extents 0
first seg id not used 0 1067667
SEGMENT id 0 1067666 space 0; page 903; res 1 used 1; full ext 0
fragm pages 1; free extents 0; not full extents 0: pages 0
...省略若干輸出
SEGMENT id 0 144216 space 0; page 1307; res 1 used 1; full ext 0
fragm pages 1; free extents 0; not full extents 0: pages 0
NUMBER of file segments: 37
Validating tablespace
Validation ok
---------------------------------------
END OF INNODB TABLESPACE MONITOR OUTPUT
=======================================


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