天天看點

[MySQL 5.6] Innodb 新的監控表 INNODB_METRICS

除了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';

|      148 |

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

|       62 |

預設打開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 thecount, max_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

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_%';

重置ahi所有列的值:

mysql> set global innodb_monitor_reset_all = “adaptive_hash_%”;

隻重置counter的值:

mysql> set global innodb_monitor_reset = “adaptive_hash_%”;

根據子產品名打開:

mysql> set global innodb_monitor_enable = module_adaptive_hash;

打開所有計數器:

mysql>  set global innodb_monitor_enable = all;

關閉所有計數器:

mysql> set global innodb_monitor_disable =  all;

我們既可以設定具體的某一個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的相關資訊