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

Innotop简单介绍的更多相关文章

  1. [原创]关于mybatis中一级缓存和二级缓存的简单介绍

    关于mybatis中一级缓存和二级缓存的简单介绍 mybatis的一级缓存: MyBatis会在表示会话的SqlSession对象中建立一个简单的缓存,将每次查询到的结果结果缓存起来,当下次查询的时候 ...

  2. 利用Python进行数据分析(7) pandas基础: Series和DataFrame的简单介绍

    一.pandas 是什么 pandas 是基于 NumPy 的一个 Python 数据分析包,主要目的是为了数据分析.它提供了大量高级的数据结构和对数据处理的方法. pandas 有两个主要的数据结构 ...

  3. 利用Python进行数据分析(4) NumPy基础: ndarray简单介绍

    一.NumPy 是什么 NumPy 是 Python 科学计算的基础包,它专为进行严格的数字处理而产生.在之前的随笔里已有更加详细的介绍,这里不再赘述. 利用 Python 进行数据分析(一)简单介绍 ...

  4. yii2的权限管理系统RBAC简单介绍

    这里有几个概念 权限: 指用户是否可以执行哪些操作,如:编辑.发布.查看回帖 角色 比如:VIP用户组, 高级会员组,中级会员组,初级会员组 VIP用户组:发帖.回帖.删帖.浏览权限 高级会员组:发帖 ...

  5. angular1.x的简单介绍(二)

    首先还是要强调一下DI,DI(Denpendency Injection)伸手获得,主要解决模块间的耦合关系.那么模块是又什么组成的呢?在我看来,模块的最小单位是类,多个类的组合就是模块.关于在根模块 ...

  6. Linux的简单介绍和常用命令的介绍

    Linux的简单介绍和常用命令的介绍 本说明以Ubuntu系统为例 Ubuntu系统的安装自行百度,或者参考http://www.cnblogs.com/CoderJYF/p/6091068.html ...

  7. iOS-iOS开发简单介绍

    概览 终于到了真正接触IOS应用程序的时刻了,之前我们花了很多时间去讨论C语言.ObjC等知识,对于很多朋友而言开发IOS第一天就想直接看到成果,看到可以运行的IOS程序.但是这里我想强调一下,前面的 ...

  8. iOS开发多线程篇—多线程简单介绍

    iOS开发多线程篇—多线程简单介绍 一.进程和线程 1.什么是进程 进程是指在系统中正在运行的一个应用程序 每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内 比如同时打开QQ.Xcod ...

  9. iOS开发UI篇—UITabBarController简单介绍

    iOS开发UI篇—UITabBarController简单介绍 一.简单介绍 UITabBarController和UINavigationController类似,UITabBarControlle ...

随机推荐

  1. 【转】判断点在多边形内(matlab)

    inpolygon -Points inside polygonal region Syntax IN = inpolygon(X,Y,xv,yv)[IN ON] = inpolygon(X,Y,xv ...

  2. 文件A包含文件B,找出A不包含B的那部分

    文件A: a f b e c d 文件B: b c a 目的:A包含B,找出A中有但B中没有的部分 代码: 首先利用dos2unix命令将windows文件转换为unix文件 dos2unix a.t ...

  3. Win和Linux查看端口和杀死进程

    title: Win和Linux查看端口和杀死进程 date: 2017-7-30 tags: null categories: Linux --- 本文介绍Windows和Linux下查看端口和杀死 ...

  4. [DeeplearningAI笔记]改善深层神经网络_深度学习的实用层面1.9_归一化normalization

    觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.9 归一化Normaliation 训练神经网络,其中一个加速训练的方法就是归一化输入(normalize inputs). 假设我们有一个 ...

  5. ABP官方文档翻译 7.3 Quartz集成

    Quartz集成 介绍 安装 创建Jobs 计划安排Jobs 更多 介绍 Quartz是一个全功能的.开源的job计划安排系统,可以用在小的apps也可以用于大型的企业系统.Abp.Quartz包简化 ...

  6. 香甜的黄油 Sweet Butter

    原题链接:https://www.luogu.org/problem/show?pid=1828#sub 经典的最短路问题. 各位不要被题目条件迷惑了,牧场想象成点,道路想象成边,奶牛所在的位置想象成 ...

  7. BZOJ 1770: [Usaco2009 Nov]lights 燈 [高斯消元XOR 搜索]

    题意: 经典灯问题,求最少次数 本题数据不水,必须要暴搜自由元的取值啦 想了好久 然而我看到网上的程序都没有用记录now的做法,那样做遇到自由元应该可能会丢解吧...? 我的做法是把自由元保存下来,枚 ...

  8. jquery参考手册

    开始使用 jQueryjQuery 本身只有一个 js 文件,所以,要使用它,就和使用其它的 js 文件一样,直接将它引入就可以使用了. <script type="text/java ...

  9. 在ASP.NET MVC中使用Web API和EntityFramework构建应用程序

    最近做了一个项目技术预研:在ASP.NET MVC框架中使用Web API和EntityFramework,构建一个基础的架构,并在此基础上实现基本的CRUD应用. 以下是详细的步骤. 第一步 在数据 ...

  10. redux简明学习

    前面的话 这几天被redux折腾的够呛,看了很多视频,也看了很多资料.很多时候,感觉好像顿悟了,但实际上只是理解了其中的一个小概念而已.真正去做项目的时候,还是会卡壳.可能是学CSS和Javascri ...