[MySQL5.6]Innodb新的監控表INNODB_METRICS

zhaiwx_yinfeng發表於2016-05-10

除了Performance Schema外,在MySQL 5.6中還提供了一個新的information_schema表來監控Innodb的內部執行狀態——INNODB_METRICS;該表維護了一組計數器,使用者可以通過這些計數器,來監控Innodb內部執行是否健康。當前的MySQL5.6.12版本中,共有210個計數器:

mysql> select count(*) from INNODB_METRICS;

+———-+

| count(*) |

+———-+

|      210 |

+———-+

1 row in set (0.00 sec)

mysql> select count(*) from innodb_metrics where status = ‘disabled`;

+———-+

| count(*) |

+———-+

|      148 |

+———-+

1 row in set (0.00 sec)

mysql> select count(*) from innodb_metrics where status = ‘enabled`;

+———-+

| count(*) |

+———-+

|       62 |

+———-+

1 row in set (0.00 sec)

預設開啟62個計數器

這裡我們不討論相關的程式碼實現,因為其實現很簡單,所有的監控項,包括跟這些計數器相關的操作都在檔案srv/srv0mon.cc中,獨立成模組,外部我們經常看到類似如下程式碼的,就是插入的計數器:

buf_LRU_get_free_block:

     MONITOR_INC(MONITOR_LRU_GET_FREE_SEARCH);

如果我們自己要新增新的counter,可以往srv/srv0mon.cc中自行新增。

以下只討論如何使用該表,以及其包含的內容。

INNODB_METRICS表包括如下列(摘自官方文件)

Column name

Description

NAME

Unique name for the counter.

SUBSYSTEM

The aspect of InnoDB that the metric applies to. See the list following the table for the corresponding module names to use with the SET GLOBAL syntax.

COUNT

Value since the counter is enabled.

MAX_COUNT

Maximum value since the counter is enabled.

MIN_COUNT

Minimum value since the counter is enabled.

AVG_COUNT

Average value since the counter is enabled.

COUNT_RESET

Counter value since it was last reset. (The _RESET fields act like the lap counter on a stopwatch: you can measure the activity during some time interval, while the cumulative figures are still available in theCOUNTMAX_COUNT, and so on fields.)

MAX_COUNT_RESET

Maximum counter value since it was last reset.

MIN_COUNT_RESET

Minimum counter value since it was last reset.

AVG_COUNT_RESET

Average counter value since it was last reset.

TIME_ENABLED

Timestamp of last start.

TIME_DISABLED

Timestamp of last stop.

TIME_ELAPSED

Elapsed time in seconds since the counter started.

TIME_RESET

Timestamp of last stop.

STATUS

Whether the counter is still running () or stopped ().

TYPE

Whether the item is a cumulative counter, or measures the current value of some resource.

COMMENT

Additional description.

例如,我們要查詢DML的執行量:

mysql>  select status,  NAME, COUNT, SUBSYSTEM from INNODB_METRICS where name like ‘%dml%`;

+———-+———————-+——-+———–+

| status   | NAME                 | COUNT | SUBSYSTEM |

+———-+———————-+——-+———–+

| disabled | purge_dml_delay_usec |     0 | purge     |

| enabled  | dml_reads            |   942 | dml       |

| enabled  | dml_inserts          |     0 | dml       |

| enabled  | dml_deletes          |     0 | dml       |

| enabled  | dml_updates          |   913 | dml       |

+———-+———————-+——-+———–+

5 rows in set (0.00 sec)

我們可以通過以下幾個變數來控制計數器的設定:

mysql> show variables like ‘%monitor%`;

+————————–+——-+

| Variable_name            | Value |

+————————–+——-+

| innodb_monitor_disable   |       |

| innodb_monitor_enable    |       |

| innodb_monitor_reset     |       |

| innodb_monitor_reset_all |       |

+————————–+——-+

4 rows in set (0.00 sec)

我們以AHI相關的計數器為例,預設情況下他們是關閉的

mysql> select status, name, subsystem from INNODB_METRICS where status = ‘disabled’ and subsystem like ‘%adaptive_hash_index%`;

+———-+——————————————+———————+

| status   | name                                     | subsystem           |

+———-+——————————————+———————+

| disabled | adaptive_hash_searches_btree             | adaptive_hash_index |

| disabled | adaptive_hash_pages_added                | adaptive_hash_index |

| disabled | adaptive_hash_pages_removed              | adaptive_hash_index |

| disabled | adaptive_hash_rows_added                 | adaptive_hash_index |

| disabled | adaptive_hash_rows_removed               | adaptive_hash_index |

| disabled | adaptive_hash_rows_deleted_no_hash_entry | adaptive_hash_index |

| disabled | adaptive_hash_rows_updated               | adaptive_hash_index |

+———-+——————————————+———————+

7 rows in set (0.00 sec)

開啟計數器:

mysql> set global innodb_monitor_enable = ‘adaptive_hash_%`;

Query OK, 0 rows affected (0.00 sec)

關閉計數器:

mysql> set global innodb_monitor_disable = ‘adaptive_hash_%`;

Query OK, 0 rows affected (0.00 sec)

重置AHI所有列的值:

mysql> set global innodb_monitor_reset_all = “adaptive_hash_%”;

Query OK, 0 rows affected (0.00 sec)

只重置COUNTER的值:

mysql> set global innodb_monitor_reset = “adaptive_hash_%”;

Query OK, 0 rows affected (0.00 sec)

根據模組名開啟:

mysql> set global innodb_monitor_enable = module_adaptive_hash;

Query OK, 0 rows affected (0.00 sec)

開啟所有計數器:

mysql>  set global innodb_monitor_enable = all;

Query OK, 0 rows affected (0.00 sec)

關閉所有計數器:

mysql> set global innodb_monitor_disable =  all;

Query OK, 0 rows affected (0.00 sec)

我們既可以設定具體的某一個counter,或者通過萬用字元,或者通過模組名,或者all,來設定counter,配置還是相當靈活的。

模組名與subsystem的對應關係:

模組名

對應subsystem

描述

module_metadata

metadata

表級別的開啟、關閉、引用次數等

module_lock

lock

鎖系統相關資訊,例如死鎖次數, 建立/移除/請求的記錄鎖,包括表鎖等統計資訊,鎖等待/持有時間等等。。

module_buffer

buffer

跟buffer pool相關的操作,

module_buf_page

buffer_page_io

buffer pool做寫操作的計數

module_os

os

os層的資料讀寫等資訊

module_trx

transaction

事務量統計,例如只讀事務,寫事務,回滾事務,活躍事務,事務Undo資訊等。

module_purge

purge

purge操作統計,例如purge 標記刪除的記錄樹,Purge undo日誌的page數等

module_compress

compression

壓縮表相關統計資訊,例如壓縮,解壓,增加/減少padding的次數等。

module_file

file_system

只有一個counter:file_num_open_files 表示開啟的檔案數

module_index

index

索引分裂和合並的次數

module_adaptive_hash

adaptive_hash_index

自適應hash相關操作

module_ibuf_system

change_buffer

change buffer相關操作統計

module_srv

server

例項內部執行狀態,例如bp size , page size ,master執行緒資訊,spin 統計,讀寫鎖資訊,寫double write buffer的計數

module_ddl

ddl

DDL統計

module_dml

dml

讀/插入/刪除/更新的次數

module_log

recovery

跟redo log相關的資訊,例如reodo checkpoinr資訊,flush 資訊,同步/非同步刷日誌點,日誌寫入量,pending的日誌請求等。。

module_icp

icp

在Innodb層的index condition pushdown的相關資訊


相關文章