Innotop简单介绍

 

Innotop介绍

 

Innotop是一款Perl脚本编写、开源、功能强大的MySQ的监控工具,它通过文本模式(命令行模式)监控,功能强大,配置简单,易于使用等等特性。Innotop这个项目位于https://github.com/innotop/innotop上。官方的介绍如下:

 

innotop is a 'top' clone for MySQL with many features and flexibility.

·         completely customizable; it even has a plugin interface

·         monitors many servers at once and can aggregate across them

The manual is embedded into the program in Perl's POD format, so it should be available through perldoc and man, and is still available online on the previous hosting (the project moved from google code to git): http://innotop.googlecode.com/svn/html/index.html

 

 

Innotop安装

 

 

在安装之前先要确定你的系统安装了Time::HiRes,Term::ReadKey,DBI,DBD::mysql这四个包。当然在执行perl Makefile.PL命令是会检查这些依赖项,如下所示:

 

 

[root@DB-Server ~]# cd /tmp
[root@DB-Server tmp]# unzip innotop-master.zip 
[root@DB-Server tmp]# cd innotop-master/
[root@DB-Serverinnotop-master]# ls
Changelog  COPYING  innotop  innotop.spec  INSTALL  Makefile.PL  MANIFEST  README.md  snapshot_queries.png  t
[root@DB-Server innotop-master]# perl Makefile.PL 
Checking if your kit is complete...
Looks good
Warning: prerequisite DBD::mysql 1 not found.
Warning: prerequisite Term::ReadKey 2.1 not found.
Writing Makefile for innotop
[root@DB-Server innotop-master]# 
[root@DB-Server innotop-master]# yum search ReadKey
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * epel: ftp.cuhk.edu.hk
================================== N/S matched: ReadKey ==========================================
perl-TermReadKey.x86_64 : A perl module for simple terminal control
 
  Name and summary matches only, use "search all" for everything.
[root@DB-Server innotop-master]# 
[root@DB-Server innotop-master]#yum install perl-TermReadKey
[root@DB-Server innotop-master]#yum install perl-DBD-MySQL
[root@DB-Server innotop-master]#  perl Makefile.PL 
Writing Makefile for innotop
[root@DB-Server innotop-master]# make
cp innotop blib/script/innotop
/usr/bin/perl -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/innotop
Manifying blib/man1/innotop.1
[root@DB-Server innotop-master]# make install
Installing /usr/local/share/man/man1/innotop.1
Installing /usr/local/bin/innotop
Appending installation info to /usr/lib64/perl5/perllocal.pod
[root@DB-Server innotop-master]# 

 

 

安装好Innotop后,有可能使用的时候,会遇到下面异常信息

 

[root@gettestlnx02 innotop-master]# innotop -u root -p123456
localhost PROCESSLIST_NO_IS: install_driver(mysql) failed: Can't load '/usr/lib64/perl5/auto/DBD/mysql/mysql.so' for module DBD::mysql: libmysqlclient.so.16: cannot open shared object file: No such file or directory at /usr/lib64/perl5/DynaLoader.pm line 200.
 at (eval 566) line 3
Compilation failed in require at (eval 566) line 3.
Perhaps a required shared library or dll isn't installed where expected
 at /usr/local/bin/innotop line 7737

 

 

这个一般是没有perl-DBD-MySQL组件,或者需要重新安装perl-DBD-MySQL组件即可(为什么重装即可解决的原因暂时不清楚,没有深入去研究这个)。

 

 #yum remove perl-DBD-MySQL

 #yum install perl-DBD-MySQL

 

 

 

 

Innotop使用

 

 

Innotop的帮助信息可以通过下面几种方式:

 

innotop --help

man innotop

perldoc innotop

 

[oracle@DB-Server admin]$ innotop --help
Usage: innotop <options> <innodb-status-file>
 
  --askpass          Prompt for a password when connecting to MySQL #当连接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 #Scoket位置
  --spark            Length of status sparkline (default 10)
  --timestamp   -t   Print timestamp in -n mode (1: per iter; 2: per line)
  --user        -u   User for login if not current user  #连接MySQL的用户
  --version          Output version information and exit #输出Innotop版本信息并退出
  --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 -uroot -pllo9kc&sq@2eq

 

innotop -uroot -p"llo9kc&sq@2eq"

 

 

 

连接成功后 输入?可以进入帮助, 另外注意快捷键的大小写, Q表示查询列表,而q表示退出。在不同模式切换可以使用SHIFT + 对应字母(也即大写字母在模式间切换)

 

 

 

 

Switch to a different mode:
   A  Dashboard         I  InnoDB I/O Info     Q  Query List
   B  InnoDB Buffers    K  InnoDB Lock Waits   R  InnoDB Row Ops
   C  Command Summary   L  Locks               S  Variables & Status
   D  InnoDB Deadlocks  M  Replication Status  T  InnoDB Txns
   F  InnoDB FK Err     O  Open Tables         U  User Statistics
 
Actions:  
   d  Change refresh interval (更改刷新间隔)           q  Quit innotop (退出innotop工具)
   k  Kill a query's connection (杀死一查询连接)       r  Reverse sort order (反向排序)
   n  Switch to the next connection(切换到下一个连接)  s  Choose sort column (选择排序字段)
   p  Pause innotop (停止innotop)                       x  Kill a query(杀死查询)
 
Other:
 TAB  Switch to the next server group  切换到另外一组服务器       /  Quickly filter what you see   快速过滤你所见信息
   !  Show license and warranty        显示License等相关信息       =  Toggle aggregation
   #  Select/create server groups      选择或创建服务器组       @  Select/create server connections 选择或创建服务器连接
   $  Edit configuration settings      编辑配置设置信息       \  Clear quick-filters           清除快速过滤设置
Press any key to continue

 

进入到交互式界面后,点击@键,就会进入到连接配置界面,如下截图所示:

 

 

 

配置好了后,就可以使用Inntop远程监控MySQL服务器了,那么如果监控多个MySQL,如何切换呢? SHIF +@就可以进入选择哪一个服务器

 

_____________________ Choose from _____________________

DB-Server   DBI:mysql:;host=10.20.57.15;port=3306   

localhost   DBI:mysql:;;mysql_read_default_group=client

 

Choose connections for this mode:

 

在Choose connections for this mode: 输入localhost按回车键就切换到本机,如果输入DB-Server按回车键就切换到DB-Server服务器。不过这种方式有一个弊端就是,Innotop退出后,这些信息就会丢失,需要重新配置,可以通过配置文件来保存。

 

默认情况下是没有innotop.conf这个配置文件的,你可以使用innotop --write进入交互界面,提示你需要输入密码,选择q退出即可,此时就会在当前目录生成.innotop/innotop.conf配置文件

 

 

[root@DB-Server ~]# innotop --write

[root@DB-Server ~]# find / -name "innotop.conf"

/root/.innotop/innotop.conf

[root@DB-Server ~]# ls .innotop/

innotop.conf  plugins

[root@DB-Server ~]# vi /root/.innotop/innotop.conf

 

 

[connections]
 
localhost=user=root have_user=1 have_pass=1 dsn=DBI:mysql:;;mysql_read_default_group=client savepass= dl_table=test.innotop_dl
mydb=user=root have_user=1 pass="xxxxxx" have_pass=1 dsn=DBI:mysql:;host=192.168.7.218;port=3306 savepass=1 dl_table=
 
[/connections]
 
[active_connections]
 
A=localhost
B=mydb
C=
D=
F=
..

 

可以在配置文件里面添加需要监控的MySQL主机,然后在active_connections下设置对应的MySQL服务器,如下所示,

 

 

localhost没有指定密码,所以默认连接到mydb这台服务器了。savepass=1 表示保存密码,savepass=0表示不保存密码。如果出于安全考虑,不要设置savepass参数,它默认为0。

 

 

 

 

本文也不打算详细讲述如何使用Innotop的各个功能,这个实在有点多,下面简单的介绍两个例子:

 

1:在Query List模式下(SHIFT+Q),你可以看到正在执行的SQL语句执行了多长时间,如下所示,我构造了一个执行时间较长的例子,那么在Query List模式下,你就可以看到脚本的执行时长,当然,执行完了后,这里就看不到相关信息了。

 

 

 

 

2:另外,在这篇博客中MySQL线程处于Waiting for table flush的分析,也介绍了Innotop使用的一个案例,如下所示:

 

对于实验中使用lock table read这种情况,这种会话可能处于Sleep状态,而且它也不会出现在show engine innodb status \G命令的输出信息中。 即使show open tables where in_use >=1;能找到是那张表被lock住了,但是无法定位到具体的线程(连接),其实这个是一个头痛的问题。但是inntop这款利器就可以定位到,如下所示,线程17锁住了表test,在innotop里面就能定位到是线程17。

 

 

 

Innotop的安装使用非常简单,工具功能也非常强大,关键还在于使用工具的人能否物尽其用,能够对各个指标深入了解,这样才能快速的分析问题、定位问题,解决问题。后续如果积累了一些使用心得和案例,再详细总结一下这个工具!

 

 

 

参考资料:

 

https://www.percona.com/blog/2013/10/14/innotop-real-time-advanced-investigation-tool-mysql/

http://www.cnblogs.com/ivictor/p/5101506.html

 

时间: 2025-02-01 14:56:27

Innotop简单介绍的相关文章

简单介绍Python2.x版本中的cmp()方法的使用

  这篇文章主要介绍了简单介绍Python2.x版本中的cmp()方法的使用,然而该方法在Python3.x版本中已并不再内置...需要的朋友可以参考下 cmp()方法比较两个列表的元素. 语法 以下是cmp()方法的语法: ? 1 cmp(list1, list2) 参数 list1 -- 这是要进行比较的第一个列表 list2 -- 这是要进行比较的第二个列表 返回值 如果元素是相同类型的,执行比较,并返回结果.如果元素是不同的类型,检查,看看他们是否是数字 如果是数字必要时强制进行数字比较

WML教程2:简单介绍关于WML文件的概念WML Decks

概念|教程 这里简单介绍一个关于WML文件的概念,其他的细节问题会在后面的章节还详细介绍. 声明由于WML语言继承于XML,所以一个有效的WML文档必须包含一个XML声明和一个文件类型声明. 以下就是一个最常用的声明,由于WML语法要求非常严格,为了避免出错,制作者可以直接拷贝粘贴到制作文档. <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" &quo

简单介绍CSS结合JS的运用

css|js 利用CSS配合Javascript的可以做很多更酷的动态页面效果,在本教程的最后给大家简单介绍一下CSS配合JS的应用.首先,我们要搞清楚事件和动作的概念.在客户端脚本中,JavaScript 通过对事件进行响应来获得与用户的交互.例如,当用户单击一个按钮或者在某段文字上移动鼠标时,就触发了一个单击事件或鼠标移动事件,通过对这些事件的响应,可以完成特定的功能(例如,单击按钮弹出对话框,鼠标移动到文本上后文本变色等). 下面介绍几种常见的事件(还用更多事件,请查阅相关资料): onC

web.config 简单介绍

web 叫做web.config当然就是配置网站用的啦 很多东西都可以在这里设置下面简单介绍一下web.config是一个xml文档(现在越来越流行用xml做配置文件了)根元素是configuration 然后包含一个system.web节点 在第三层次是对站点的各种设置web.config可以设置的标签非常之多,那么,简单的做个介绍,当用到的时候可以去好好查阅在web系统中自定义的设置 我经常使用它来保存数据库的一些相关连接数据 之后读取很方便关于浏览器的设置 比如是否允许JavaApplet

简单介绍几个通用的设计原则

经常会听到有人议论,设计很主观化,很难有标准.但一些常见设计法则,还是能够让我们深入浅出,在设计过程中给予我们一些辅助.以下就简单介绍几个: 1.Flexibility-Usability Tradeoff 弹性-使用性权衡 弹性,即样样知晓,无一精通.当弹性增加时,单个功能的使用性就会降低,引发效率降低,复杂性.时间以及开发的成本增加. 如何兼顾功能的丰富和使用性,弹性需求在何种情况下是有意义的?简单来说,用户对其未来需求没有清楚的期望值时,可以多做一些功能去试探用户的功能需求.如,拥有多功能

DNN调度管理解析(一)-----简单介绍及其API

简单介绍 调度管理是DNN提供给开发者在一定的时间间隔实现调度任务的一种机制. 类似,它也是在提供者模式的基础上实现的,所以可以不更改核心代码就创建新的或修改原有的调度服务.查看有关资料你会发现这是DNN核心团队的成员Dan Caron 的巨大贡献: It was during this time that Dan Caron single-handedly made a significant impact on the project. Based on his experience wit

PHP.ini安全配置检测工具pcc简单介绍

  这篇文章主要介绍了PHP.ini安全配置检测工具pcc简单介绍,这款工具非常实用,可以检测PHP配置文件中得配置项是否存在安全隐患,并提出相应的配置建议,需要的朋友可以参考下 概述 前一段时间,在工作中遇到了一个开源程序,该程序主要用来检测PHP配置文件中得配置项是否存在安全隐患,并提出相应的配置建议,使PHP程序更加安全. 使用 这个程序使用起来非常简单,大家可以自行使用.下面是程序运行截图:

简单介绍JavaScript的变量和数据类型

  这篇文章主要介绍了简单介绍JavaScript的变量和数据类型,是JS入门中的基础知识,需要的朋友可以参考下 JavaScript数据类型: 编程语言的最根本的特征之一是一组它支持的数据类型.这些是可被表示和操纵的编程语言的值的类型. JavaScript允许有三个基本数据类型: 数字如. 123, 120.50 等. 字符串如 "This text string" 等. 布尔类型,如 true 或 false. 的JavaScript还定义了两种数据类型:null和undefin

简单介绍Python的Django框架的dj-scaffold项目

  这篇文章主要介绍了简单介绍Python的Django框架的dj-scaffold项目,用于辅助Django框架的目录设置,需要的朋友可以参考下 由于Django没有象rails一样指定项目的目录结构规范,很多人都对django项目的目录结构要如何组织而感到困惑.为此我又新创建了一个开源项目dj-scaffold(django的脚手架).这个项目用于自动生成一个标注化的django项目和app. 项目地址:https://github.com/vicalloy/dj-scaffold 安装 已