MySQL5.6監控表之INNODB_METRICS


http://blog.chinaunix.net/uid-10661836-id-4278807.html

 

在MySQL5.6的Information_Schema引入新的INNODB_METRICS,此表用來監控InnoDB運行是否正常,並且該表包括很多計數器
mysql> select version();
+------------------+
| version()        |
+------------------+
| 5.6.28-debug-log |
+------------------+
1 row in set (0.00 sec)

此表的結構:

mysql> desc INNODB_METRICS;
+-----------------+--------------+------+-----+---------+-------+
| Field           | Type         | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| NAME            | varchar(193) | NO   |     |         |       |
| SUBSYSTEM       | varchar(193) | NO   |     |         |       |
| COUNT           | bigint(21)   | NO   |     | 0       |       |
| MAX_COUNT       | bigint(21)   | YES  |     | NULL    |       |
| MIN_COUNT       | bigint(21)   | YES  |     | NULL    |       |
| AVG_COUNT       | double       | YES  |     | NULL    |       |
| COUNT_RESET     | bigint(21)   | NO   |     | 0       |       |
| MAX_COUNT_RESET | bigint(21)   | YES  |     | NULL    |       |
| MIN_COUNT_RESET | bigint(21)   | YES  |     | NULL    |       |
| AVG_COUNT_RESET | double       | YES  |     | NULL    |       |
| TIME_ENABLED    | datetime     | YES  |     | NULL    |       |
| TIME_DISABLED   | datetime     | YES  |     | NULL    |       |
| TIME_ELAPSED    | bigint(21)   | YES  |     | NULL    |       |
| TIME_RESET      | datetime     | YES  |     | NULL    |       |
| STATUS          | varchar(193) | NO   |     |         |       |
| TYPE            | varchar(193) | NO   |     |         |       |
| COMMENT         | varchar(193) | NO   |     |         |       |
+-----------------+--------------+------+-----+---------+-------+
17 rows in set (0.19 sec)

總計數器:

mysql>  select count(*) from INNODB_METRICS;
+----------+
| count(*) |
+----------+
|      214 |
+----------+
1 row in set (0.19 sec)

默認開啟的計數器

mysql> select count(*) from innodb_metrics where status = 'enabled'; 
+----------+
| count(*) |
+----------+
| 63 |
+----------+
1 row in set (0.18 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)

我們以metadata相關的計數器為例,演示開啟、關閉、重置.默認此計數器是關閉狀態.

mysql> select status, name, subsystem from INNODB_METRICS where status = 'disabled' and subsystem='metadata';
+----------+--------------------------------+-----------+
| status   | name                           | subsystem |
+----------+--------------------------------+-----------+
| disabled | metadata_table_handles_opened  | metadata  |
| disabled | metadata_table_handles_closed  | metadata  |
| disabled | metadata_table_reference_count | metadata  |
+----------+--------------------------------+-----------+
3 rows in set (0.01 sec)

開啟:

mysql>  set global innodb_monitor_enable = 'metadata_%';
Query OK, 0 rows affected (0.01 sec)
mysql>  select status, name, subsystem from INNODB_METRICS where subsystem='metadata';
+---------+--------------------------------+-----------+
| status  | name                           | subsystem |
+---------+--------------------------------+-----------+
| enabled | metadata_table_handles_opened  | metadata  |
| enabled | metadata_table_handles_closed  | metadata  |
| enabled | metadata_table_reference_count | metadata  |
| enabled | metadata_mem_pool_size         | metadata  |
+---------+--------------------------------+-----------+
4 rows in set (0.01 sec)

關閉:

mysql> set global innodb_monitor_disable = 'metadata_%';
Query OK, 0 rows affected (0.00 sec)

重置所有metadata的所有值:

mysql>  set global innodb_monitor_reset_all = 'metadata_%';
Query OK, 0 rows affected (0.00 sec)

 



重置計數器值:
mysql>  set global innodb_monitor_reset = 'metadata_%';
Query OK, 0 rows affected (0.00 sec)

 



打開與關閉所有計數器
mysql> set global innodb_monitor_disable = all;
Query OK, 0 rows affected (0.18 sec)

mysql>  set global innodb_monitor_enable = all;
Query OK, 0 rows affected (0.00 sec)

 

計數器既支持單個開啟也支持模糊匹配,所以配置起來還是非常靈活多變的.

模塊對應的子系統(此翻譯為個人理解,如有錯誤請指出.)
module_metadata (subsystem = metadata)           表計數器開啟、關閉

module_lock (subsystem = lock)                            鎖監控死鎖、表鎖,鎖統計信息等等.

module_buffer (subsystem = buffer)                     buffer_pool

module_buf_page (subsystem = buffer_page_io)        buffer的寫操作

module_os (subsystem = os)                                        操作系統信息

module_trx (subsystem = transaction)                           事務信息監控回滾、只讀事務等等信息

module_purge (subsystem = purge)                               purge刪除信息

module_compress (subsystem = compression)              表壓縮相關信息

module_file (subsystem = file_system)                           打開文件數

module_index (subsystem = index)                                索引相關信息,統計索引信息、索引分裂等等

module_adaptive_hash (subsystem = adaptive_hash_index)     自適應哈希

module_ibuf_system (subsystem = change_buffer)                  '這個還不知道'囧

module_srv (subsystem = server)                                            server運行狀態信息

module_ddl (subsystem = ddl)                                                  ddl信息

module_dml (subsystem = dml)                                               讀、寫、更新、刪除信息

module_log (subsystem = recovery)                                         flush,同步異步刷日志等等信息

module_icp (subsystem = icp)                                                   icp通信? 囧,'這個不知道怎么理解'
 


這里舉個例子以dml_insert為例
 
mysql> select name,subsystem,status,count from information_schema.innodb_metrics  where name like "dml%";
+-------------+-----------+----------+-------+
| name        | subsystem | status   | count |
+-------------+-----------+----------+-------+
| dml_reads   | dml       | disabled |     0 |
| dml_inserts | dml       | disabled |     0 |
| dml_deletes | dml       | disabled |     0 |
| dml_updates | dml       | disabled |     0 |
+-------------+-----------+----------+-------+
 mysql>  set global innodb_monitor_enable = 'dml_inserts';
 Query OK, 0 rows affected (0.00 sec)

  mysql> select status, name, subsystem from INNODB_METRICS where status = 'enabled' and subsystem='dml';
  +---------+-------------+-----------+
  | status  | name      | subsystem |
  +---------+-------------+-----------+
  | enabled | dml_inserts | dml      |
  +---------+-------------+-----------+
  1 row in set (0.00 sec)



mysql>  select * from information_schema.innodb_metrics where name='dml_inserts'\G;
*************************** 1. row ***************************
           NAME: dml_inserts
      SUBSYSTEM: dml
          COUNT: 0
      MAX_COUNT: 0
      MIN_COUNT: NULL
      AVG_COUNT: 0
    COUNT_RESET: 0
MAX_COUNT_RESET: 0
MIN_COUNT_RESET: NULL
AVG_COUNT_RESET: NULL
   TIME_ENABLED: 2016-06-27 21:30:56
  TIME_DISABLED: NULL
   TIME_ELAPSED: 138
     TIME_RESET: NULL
         STATUS: enabled
           TYPE: status_counter
        COMMENT: Number of rows inserted
1 row in set (0.21 sec)

測試:

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create table test (id int);
Query OK, 0 rows affected (0.24 sec)

mysql> insert into test values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
Query OK, 10 rows affected (0.21 sec)
Records: 10  Duplicates: 0  Warnings: 0

mysql> insert into test values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
Query OK, 10 rows affected (0.18 sec)
Records: 10  Duplicates: 0  Warnings: 0

mysql> insert into test values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
Query OK, 10 rows affected (0.01 sec)
Records: 10  Duplicates: 0  Warnings: 0

mysql> insert into test values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
Query OK, 10 rows affected (0.01 sec)
Records: 10  Duplicates: 0  Warnings: 0

mysql> insert into test values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
Query OK, 10 rows affected (0.01 sec)
Records: 10  Duplicates: 0  Warnings: 0

mysql> select * from information_schema.innodb_metrics where name='dml_inserts'\G;
*************************** 1. row ***************************
           NAME: dml_inserts
      SUBSYSTEM: dml
          COUNT: 50
      MAX_COUNT: 50
      MIN_COUNT: NULL
      AVG_COUNT: 0.04950495049504951
    COUNT_RESET: 50
MAX_COUNT_RESET: 50
MIN_COUNT_RESET: NULL
AVG_COUNT_RESET: NULL
   TIME_ENABLED: 2016-06-27 21:30:56
  TIME_DISABLED: NULL
   TIME_ELAPSED: 1010
     TIME_RESET: NULL
         STATUS: enabled
           TYPE: status_counter
        COMMENT: Number of rows inserted
1 row in set (0.19 sec)

 

這時我們重置計數器
mysql>  set global innodb_monitor_reset = module_dml;
Query OK, 0 rows affected (0.00 sec)

mysql>  select * from information_schema.innodb_metrics where name='dml_inserts'\G;
*************************** 1. row ***************************
           NAME: dml_inserts
      SUBSYSTEM: dml
          COUNT: 50
      MAX_COUNT: 50
      MIN_COUNT: NULL
      AVG_COUNT: 0.04428697962798937
    COUNT_RESET: 0
MAX_COUNT_RESET: 0
MIN_COUNT_RESET: NULL
AVG_COUNT_RESET: 0
   TIME_ENABLED: 2016-06-27 21:30:56
  TIME_DISABLED: NULL
   TIME_ELAPSED: 1129
     TIME_RESET: 2016-06-27 21:49:34
         STATUS: enabled
           TYPE: status_counter
        COMMENT: Number of rows inserted
1 row in set (0.01 sec)

 

當我們重置計數器的時候,只會影響count_reset、max_count_reset.(不知道會不會影響avg_count_reset)

那么如果我們重置所有,那么它會把所有值全部重置
mysql> set global innodb_monitor_disable  = module_dml;
Query OK, 0 rows affected (0.00 sec)

mysql>  set global innodb_monitor_reset_all = module_dml;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from information_schema.innodb_metrics  where name='dml_inserts'\G
*************************** 1. row ***************************
           NAME: dml_inserts
      SUBSYSTEM: dml
          COUNT: 0
      MAX_COUNT: NULL
      MIN_COUNT: NULL
      AVG_COUNT: NULL
    COUNT_RESET: 0
MAX_COUNT_RESET: NULL
MIN_COUNT_RESET: NULL
AVG_COUNT_RESET: NULL
   TIME_ENABLED: NULL
  TIME_DISABLED: NULL
   TIME_ELAPSED: NULL
     TIME_RESET: NULL
         STATUS: disabled
           TYPE: status_counter
        COMMENT: Number of rows inserted
1 row in set (0.00 sec)

此文章部分內容參考MySQL官方文檔和Oracle英文Blog,地址如下:

https://blogs.oracle.com/mysqlinnodb/entry/get_started_with_innodb_metrics


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM