[MySQL 5.6] Innodb 新的监控表 INNODB_METRICS

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

除了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的相关信息


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
12天前
|
存储 监控 关系型数据库
轻松入门Mysql:MySQL性能优化与监控,解锁进销存系统的潜力(23)
轻松入门Mysql:MySQL性能优化与监控,解锁进销存系统的潜力(23)
|
24天前
|
SQL 监控 关系型数据库
MySQL性能调优:监控和优化
MySQL性能调优:监控和优化
51 1
|
Oracle 关系型数据库 MySQL
【mysql】—— 表的内连和外连
【mysql】—— 表的内连和外连
|
1月前
|
存储 关系型数据库 MySQL
【mysql】—— 表的增删改查
【mysql】—— 表的增删改查
|
14天前
|
存储 SQL 关系型数据库
【MySQL】4. 表的操作
【MySQL】4. 表的操作
19 0
|
5天前
|
存储 关系型数据库 MySQL
MySQL引擎对决:深入解析MyISAM和InnoDB的区别
MySQL引擎对决:深入解析MyISAM和InnoDB的区别
13 0
|
12天前
|
存储 关系型数据库 MySQL
MySQL数据库性能大揭秘:表设计优化的高效策略(优化数据类型、增加冗余字段、拆分表以及使用非空约束)
MySQL数据库性能大揭秘:表设计优化的高效策略(优化数据类型、增加冗余字段、拆分表以及使用非空约束)
|
12天前
|
缓存 关系型数据库 MySQL
MySQL 查询优化:提速查询效率的13大秘籍(索引设计、查询优化、缓存策略、子查询优化以及定期表分析和优化)(中)
MySQL 查询优化:提速查询效率的13大秘籍(索引设计、查询优化、缓存策略、子查询优化以及定期表分析和优化)(中)
|
14天前
|
关系型数据库 MySQL
【MySQL】12. 表的内连和外连(重点)
【MySQL】12. 表的内连和外连(重点)
12 0
|
1月前
|
存储 关系型数据库 MySQL
【mysql】—— 表的约束
【mysql】—— 表的约束

推荐镜像

更多