MySQL监控工具之Innotop介绍
简介
Innotop是一款Perl脚本编写、开源、功能强大的MySQL的监控工具。它拥有功能强大,配置简单,易于使用等等特性。INNOTOP是用PERL语言写成的,通过文本模式,它能详细的监控出当前MYSQL和INNODB运行的状态,以便维护人员根据结果合理的优化MYSQL,让MYSQL更稳定更高效的运行。
安装
下载地址:https://github.com/innotop/innotop
Github上提供两种版本:
- 一种是开发版(innotop-master)
- 一种是稳定版(innotop-gtid)
1 2 3 4 5 6 7 | yum install -y perl-TermReadKey wget https://github.com/innotop/innotop/archive/refs/tags/v1.13.0.tar.gz tar -zxvf v1.13.0.tar.gz cd innotop-master perl Makefile.PL cp innotop /usr/local/bin/ |
使用
帮助信息
Innotop的帮助信息可以通过下面几种方式:
- innotop --help
- man innotop
- perldoc innotop
首先我们通过innotop --help
查看其常见的启动参数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | [root@lhrdb ~]# innotop --help Usage: innotop <options> <innodb-status-file> --askpass Prompt for a password when connecting to MySQL --[no]color -C Use terminal coloring (default) --config -c Config file to read --count Number of updates before exiting --delay -d Delay between updates in seconds --help Show this help message --host -h Connect to host --[no]inc -i Measure incremental differences --mode -m Operating mode to start in --nonint -n Non-interactive, output tab-separated fields --password -p Password to use for connection --port -P Port number to use for connection --skipcentral -s Skip reading the central configuration file --socket -S MySQL socket to use for connection --spark Length of status sparkline (default 10) --ssl Passed to mysql_ssl --ssl_ca_file Passed to mysql_ssl_ca_file --ssl_ca_path Passed to mysql_ssl_ca_path --ssl_cipher Passed to mysql_ssl_cipher --ssl_client_cert Passed to mysql_ssl_client_cert --ssl_client_key Passed to mysql_ssl_client_key --ssl_verify_server_cert Passed to mysql_ssl_verify_server_cert --timestamp -t Print timestamp in -n mode (1: per iter; 2: per line) --user -u User for login if not current user --version Output version information and exit --write -w Write running configuration into home directory if no config files were loaded innotop is a MySQL and InnoDB transaction/status monitor, like 'top' for MySQL. It displays queries, InnoDB transactions, lock waits, deadlocks, foreign key errors, open tables, replication status, buffer information, row operations, logs, I/O operations, load graph, and more. You can monitor many servers at once with innotop. |
在命令行输入 innotop -u <username> -p <password> -h <hostname> -P <port>
即可连接需要监控的数据库,如果密码中有特殊字符,最好使用双引号将密码括起来。
工具演示
使用innotop连接数据库,进入交互式操作界面后,可输入不同工作模式的快捷键,进行切换工作模式。可输入“?”查看如何进入各种工作模式,如下图所示。
下面详细介绍几种常用工作模式的作用和进入方法。
1)Dashboard(仪表盘)
在交互式界面,默认进入仪表盘工作模式,在切换至其他工作模式后,使用大写的"A"字母进入该工作模式或者在非交互式模式下使用-m选项指定大写的"A"字母即可进入该工作模式,如下图所示:
输出信息的含义如下:
- Uptime:当前MySQL Server持续运行了多长时间,上图414d表示414天;
- QPS:当前数据库中的QPS;
- Cxns:当前数据库中的客户端连接数;
- Run:当前数据库中正在执行查询(Query状态的)的客户端连接数;
- Miss:查询未命中buffer pool缓存的次数;
- Lock:发生锁等待的数量;
- Tbls:历史打开表数量,从状态变量Open_tables获取值。
2)InnoDB I/O Info(InnoDB I/O线程信息)
进入交互式界面之后,使用大写的"I"字母或者在非交互式模式下使用-m选项指定大写的"I"字母即可进入该工作模式,如下图所示:
输出信息的含义如下:
- I/O threads:显示当前的IO相关的线程状态信息;
- Pending I/O:显示当前处于Pending状态的I/O操作信息;
- File I/O Misc:文件I/O相关的操作统计信息(包含所有数据文件的文件I/O操作);
- Log Statistics:redo log的当前LSN号、已经刷新到磁盘的LSN号、最近一次checkpoint的LSN号,以及redo log的总IO数量,平均每秒IO数量。
3)Query List(查询语句列表信息)
进入交互式界面之后,使用大写的"Q"字母或者是非交互式模式下使用-m选项指定大写的"Q"字母即可进入该工作模式,如下图示:
输出信息的含义如下:
--统计信息头部部分
- When:为now表示当前实时的统计信息,为Total表示历史总的统计信息;
- Load:当前数据库实例的CPU负载;
- Cxns:当前数据库实例中的客户端连接数;
- QPS:当前数据库实例中的QPS;
- Slow:当前数据库实例中的慢查询数量;
- Se/In/Up/De%:增删改查比例;
- QCacheHit:QC 命中率;
- KCacheHit:索引缓存命中率;
- BpsIn:读入到buffer pool中的数据量;
- BpsOut:从buffer pool中读出的数据量。
--查询列表部分(通过执行show full processlist语句抓取)
- Cmd:语句的command类型;
- ID:查询线程ID;
- State:查询线程状态;
- User:查询线程用户;
- Host:查询线程主机名;
- DB:查询线程默认数据库名;
- Time:查询线程处于某个状态的持续时间;
- Query:查询线程当前正在执行的SQL语句文本。
4)Locks(查看Server层锁信息)
进入交互式界面之后,使用大写的"L"字母或者是非交互式模式下使用-m选项指定大写的"L"字母即可进入该工作模式,如下图所示:
输出信息的含义如下:
- InnoDB Locks:InnoDB 的记录锁统计信息;
- ID:正在等待锁的线程ID;
- Type:正在等待的锁类型;
- Waiting:正在等待多少把锁;
- Wait:锁等待时间(时间格式);
- Active:线程活跃时间;
- Mode:锁模类型;
- DB:正在等待的锁所在的数据库;
- Table:正在等待的锁所在的表;
- Index:正在等待的锁所在的索引;
- Ins Intent:插入意向锁的个数;
- Special:特殊信息,对锁进行描述,例如:rec but not gap,表示是记录锁,但不是范围锁。