前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >工具:结构化输出innodb status

工具:结构化输出innodb status

作者头像
用户5548425
发布2020-03-31 16:14:39
8310
发布2020-03-31 16:14:39
举报
文章被收录于专栏:韩锋频道韩锋频道

InnoDB Status,是MySQL InnoDB引擎对外开放的一个窗口,通过它可以了解内部运行状态。但其对外输出的形式不太友好,是一种非结构化的输出。一方面查看起来不太方便;另一方面也不容易对比运行的状态或抽取部分信息放在自己的监控平台上。本文通过自己开发的Python脚本,可以方便查看。

1. "Show InnoDB Status"概述

InnoDB存储引擎在SHOW ENGINE INNODB STATUS输出中,老版本中对应的是SHOW INNODB STATUS。

1). 平均值(采样间隔)

输出内容包含了一些平均值的统计信息,例如fsync()每秒调用次数。这些平均值是自上次输出结果生成以来的统计数。因此如果正在检查这些值,要确保已经等待了30s左右的时间,使两次采样之间积累足够长的时间并多次采样,检查计数器变化从而弄清其行为。并不是所有的输出都会在一个时间点上生成,因而也不是所有显示出来的平均值会在同一时间间隔里重新计算一遍。而且,InnoDB有一个内部复位间隔,而它是不可预知的,各个版本不一样。

2). 查看方式

  • Innotop 可查看部分信息,但是基于Perl产品,过于古老了。
  • 命令行 下面方式可显示指定栏目,并用颜色标注栏目标题,但仅仅是查看方便,不会解析内容。 mysql -uroot -e "show engine innodb status\G"|grep -E -A4 -B1 --color '^TRANSACTIONS|LOG|ROW OPERATIONS'
  • 数据字典 例如INNODB_BUFFER_POOL_STATS,但只有部分内容。

★正是基于上面原因,考虑自己写个脚本解析输出。

2. InnoDB Status输出解读(5.7)

1). 头部信息

输出的第一段是头部信息,它仅仅是代表输出的开始,其内容包括当前的日期和时间,以及自上次输出以来经过的时长。

2). SEMAPHORE

这部分主要显示系统中当前的信号等待信息及各种等待信号的统计信息,这部分信息对于调整innodb_thread_concurrency参数有帮助。当等待信号量非常大的时候,可能就需要禁用并发线程检测设置innodb_thread_concurrency=0。如果是高并发的工作环境,需要关注这一段信号量。它包含了两种数据:时间计数器,以及可选的当前等待线程的列表。如果有性能瓶颈,可用这些信息来帮你找到瓶颈所在。

3). LATEST FOREIGN KEY ERROR

一般不会出现这个信息,除非在服务器上发生一个外键错误。

4). LATEST DETECTED DEADLOCK

只有在服务器内有死锁发生才会出现。

5). TRANSACTION

InnoDB事务的摘要信息。显示系统的锁等待信息和当前活动事务信息。通过这部分,可以追踪到死锁的详细信息。

6). FILE I/O

FILE I/O段显示的是I/O helper线程的状态,用性能计数器的方式来表示。文件IO相关信息,主要是IO等待信息。

7). INSERT BUFFER AND ADAPTIVE HASH INDEX

显示插入缓存当前状态信息及自适应Hash Index的状态。

8). LOG

显示的InnoDB事务LOG子系统的统计信息。InnoDB事务日志相关信息,包括当前的日志序列号(log sequence number),已经刷新同步到哪个序列号,最近的Check Point到哪个序列号。除此之外,还显示了系统从启动到现在已经做了多少次Check Point,多少次日志刷新。

9). BUFFER POOL AND MEMORY

显示InnoDB Buffer Pool相关的各种统计信息,以及其他一些内存使用的信息。

10). ROW OPERATIONS

显示的是与客户端的请求Query和Query所影响的记录统计信息。

3. 部分指标说明(5.7)

  • Total memory allocated The total memory allocated for the buffer pool in bytes.
  • Dictionary memory allocated The total memory allocated for the InnoDB data dictionary in bytes.
  • Buffer pool size The total size in pages allocated to the buffer pool.
  • Free buffers The total size in pages of the buffer pool free list.
  • Database pages The total size in pages of the buffer pool LRU list.
  • Old database pages The total size in pages of the buffer pool old LRU sublist.
  • Modified db pages The current number of pages modified in the buffer pool.
  • Pending reads The number of buffer pool pages waiting to be read in to the buffer pool.
  • Pending writes LRU The number of old dirty pages within the buffer pool to be written from the bottom of the LRU list.
  • Pending writes flush list The number of buffer pool pages to be flushed during checkpointing.
  • Pending writes single page The number of pending independent page writes within the buffer pool.
  • Pages made young The total number of pages made young in the buffer pool LRU list (moved to the head of sublist of "new" pages).
  • Pages made not young The total number of pages not made young in the buffer pool LRU list (pages that have remained in the "old" sublist without being made young).
  • youngs/s The per second average of accesses to old pages in the buffer pool LRU list that have resulted in making pages young.
  • non-youngs/s The per second average of accesses to old pages in the buffer pool LRU list that have resulted in not making pages young.
  • Pages read The total number of pages read from the buffer pool.
  • Pages created The total number of pages created within the buffer pool.
  • Pages written The total number of pages written from the buffer pool.
  • reads/s The per second average number of buffer pool page reads per second.
  • creates/s The per second average number of buffer pool pages created per second.
  • writes/s The per second average number of buffer pool page writes per second.
  • Buffer pool hit rate The buffer pool page hit rate for pages read from the buffer pool memory vs from disk storage.
  • young-making rate The average hit rate at which page accesses have resulted in making pages young.
  • not (young-making rate) The average hit rate at which page accesses have not resulted in making pages young.
  • Pages read ahead The per second average of read ahead operations.
  • Pages evicted without access The per second average of the pages evicted without being accessed from the buffer pool.
  • Random read ahead The per second average of random read ahead operations.
  • LRU len The total size in pages of the buffer pool LRU list.
  • unzip_LRU len The total size in pages of the buffer pool unzip_LRU list.
  • I/O sum The total number of buffer pool LRU list pages accessed, for the last 50 seconds.
  • I/O cur The total number of buffer pool LRU list pages accessed.
  • I/O unzip sum The total number of buffer pool unzip_LRU list pages accessed.
  • I/O unzip cur The total number of buffer pool unzip_LRU list pages accessed.

4. 脚本说明

1). 准备条件

  • 模块 - MySQLDB
  • Python版本 >= 2.6.x (3.x版本不支持)

2). 使用方法

Usage:

./mysql_innodb_status.py

-h : database ip address/domain name

-u : username

-p : password

-k : print specified items(section.key1,section.key2) or section.*

-n : interval time

-w : width

3). 使用示例

python mysql_innodb_status.py

-h localhost -u testuser -p testpwd

-k all -n 5

python mysql_innodb_status.py

-h localhost -u testuser -p testpwd

-k row_operations.* -n 5

python mysql_innodb_status.py

-h localhost -u testuser -p testpwd

-k row_operations.reads_per_second -n 50

4). 源码地址

https://github.com/bjbean/parse-mysql-innodb-status/blob/master/show-innodb-status-v2.py

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-03-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 韩锋频道 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MySQL
腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档