Mytop-如何监视MySql性能
Mytop是一个非常有用的程序,用于查看服务器当前正在处理的所有查询以及正在执行的用户。
将mytop视为mysql的顶层。
如果我们从一个特定用户那里看到很多东西,那意味着他们很可能是Pig。
如果我们拥有一个自行设计的,Mytop还可用于准确确定导致问题的查询。
Mytop是用于监视mysql服务器性能的实用程序。
如果我们是普通Linux用户,则可能已经了解用于监视运行系统的Linux实用工具top。
Mytop是一个类似的实用程序,用于监视性能并列出mysql服务器的线程。
mytop由Jeremy D. Zawodny开发和维护,mytop在GNU GPL(版本2)下发布,并且也可用于Windows。
本教程概述了mytop工具。
安装Mytop
Mytop可以从Jeremy下载。
它需要一些其他软件包才能正常运行。
确保在系统上安装了以下软件包:
Perl 5.005 or newer Config::IniFiles Getopt::Long DBI::mysql and DBD::mysql Term::ReadKey from CPAN
Term :: ReadKey可以从CPAN下载
其他系统可能会安装在大多数系统上。
如果要在mytop中支持颜色,请从CPAN安装Term :: ANSIColor。
安装了所有这些功能之后,系统现在可以运行mytop了。
运行Mytop
Mytop语法很简单,如下所示:
mytop [options]
默认情况下,mytop使用用户名作为“ root”,没有密码。
我们可以使用“ -u用户”选项指定用户,并使用“ -p密码”指定密码。
提供所需的密码后,mytop将为我们显示一个交互式屏幕,如下所示:
MySQL on localhost (5.1.63-0ubuntu0.11.04.1) up 0+01:45:40 [10:40:38] Queries: 1.1k qps: 0 Slow: 0.0 Se/In/Up/De(%): 00/00/00/00 qps now: 0 Slow qps: 0.0 Threads: 2 ( 1/0) 00/00/00/00 Key Efficiency: 100.0% Bps in/out: 4.0/649.7 Now in/out: 8.4/1.5k Id User Host/IP DB Time Cmd Query or State -- ---- ------- -- ---- --- ------------- 40 root localhost 0 Query show full processlist 35 igi localhost 5024 Sleep
Mytop是一个交互式命令。
一旦运行它,它将等待用户输入,并且提示丢失。
要退出mytop,只需点击“ q”。
展示
Mytop输出分为两部分。
第一部分是标题,此处显示前4行:
MySQL on localhost (5.1.63-0ubuntu0.11.04.1) up 0+01:45:40 [10:40:38] Queries: 1.1k qps: 0 Slow: 0.0 Se/In/Up/De(%): 00/00/00/00 qps now: 0 Slow qps: 0.0 Threads: 2 ( 1/0) 00/00/00/00 Key Efficiency: 100.0% Bps in/out: 4.0/649.7 Now in/out: 8.4/1.5k
第一行显示服务器的主机名(此处为“ localhost”)和带平台的mysql版本(5.1.63-0ubuntu0.11.04.1)。
它还以“天+小时:分钟:秒”和当前时间显示mysql服务器的正常运行时间。
第二行显示已处理的查询总数,每秒的平均查询数,慢速查询的平均数以及SELECT,INSERT,UPDATE和DELETE查询的百分比。
第三行类似于第二行,但是显示实时值。
第四行是服务器性能。
例如,它显示了密钥效率:从缓冲区读取的密钥数量比从硬盘读取的密钥数量大。
它跟踪到目前为止已发送和接收的字节数以及实时值(即在最后一个周期中)。
第二部分显示服务器正在处理的线程。
Id User Host/IP DB Time Cmd Query or State -- ---- ------- -- ---- --- ------------- 40 root localhost 0 Query show full processlist 35 igi localhost 5024 Sleep
上面的输出中显示以下信息:
Thread IDs User connected with server Hostname from which a user is connected The database they are connected to Idle time Command executed by thread Query info of the thread
默认情况下,这些线程按其空闲时间排序。
与mytop互动
我们可以按“?
”查看mytop输出中在任何给定时间可用的命令。
当我们按“?
”时,将显示以下内容:
Jeremy D. Zawodny提供的针对mytop 1.6版本的帮助<[email protected]>
? - display this screen # - toggle short/long numbers (not yet implemented) c - command summary view (based on Com_* counters) d - show only a specific database e - explain the query that a thread is running f - show full query info for a given thread F - unFilter the dispaly h - show only a specifc host's connections H - toggle the mytop header i - toggle the display of idle (sleeping) threads I - show innodb status k - kill a thread p - pause the display m - switch [mode] to qps (queries/sec) scrolling view o - reverse the sort order (toggle) q - quit r - reset the status counters (via FLUSH STATUS on your server) s - change the delay between screen updates t - switch to thread view (default) u - show only a specific user : - enter a command (not yet implemented)
访问Jeremy以获取更多帮助
Mytop配置文件
Mytop为我们提供了许多命令行选项,用于指定用户名,密码,主机名,要连接的数据库,端口号等。
但是所有这些参数都可以存储在主目录中的配置文件中,因此我们不必每次运行mytop时都必须在命令行中提供它们。
mytop命令的手册页中给出的示例配置文件是:
user=root pass= host=localhost db=test delay=5 port=3306 socket= batchmode=0 header=1 color=1 idle=1
在这个档案中
user is the username with which command is run (default: root), pass is the password for that user (default none), host is hostname of mysql server (dafault: localhost), db is the database to connect to (default: none), delay is the delay (in seconds) between refreshing the myoutput screen (default: 5), port specifies the port at which mysql is running (default: 3306), socket is the location of socket file, if connection is to be made through socket instead of standard tcp/ip connection (default: none), batchmode specifies if the command is to be run non interactively, just once and exit (default: unset (or 0)), If header is 0 (or noheader), header part will not be displayed. Header can be toggled with h key later (default is header (1)), color specifies if you want colors in the output or not (default is color, if you have color support), idle species whether you want to display idle threads or not (default: 1).
必须将其存储在用户主目录中名为“ .mytop”的文件中(隐藏文件)。