GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  MYTOP (1)

.ds Aq ’

NAME

mytop - display MySQL server performance info like ‘top’

CONTENTS

SYNOPSIS

<B>mytopB> [options]

AVAILABILITY

The latest version of <B>mytopB> is available from http://jeremy.zawodny.com/mysql/mytop/ it might also be on CPAN as well.

REQUIREMENTS

In order for <B>mytopB> to function properly, you must have the following:



  * Perl 5.005 or newer
  * Getopt::Long
  * DBI and DBD::mysql
  * Term::ReadKey from CPAN



Most systems are likely to have all of those installed—except for Term::ReadKey. You will need to pick that up from the CPAN. You can pick up Term::ReadKey here:



    http://search.cpan.org/search?dist=TermReadKey



And you obviously need access to a MySQL server (version 3.22.x or 3.23.x) with the necessary security to run the SHOW PROCESSLIST and SHOW GLOBAL STATUS commands.

If you are a Windows user, using ActiveState’s Perl, you can use PPM (the Perl Package Manager) to install the MySQL and Term::ReadKey modules.

    Optional Color Support

In additon, if you want a color <B>mytopB> (recommended), install Term::ANSIColor from the CPAN:



    http://search.cpan.org/search?dist=ANSIColor



Once you do, <B>mytopB> will automatically use it. However, color is not yet working on Windows. Patches welcome. :-)

    Optional Hi-Res Timing

If you want <B>mytopB> to provide more accurate real-time queries-per-second statistics, install the Time::HiRes module from CPAN. <B>mytopB> will automatically notice that you have it and use it rather than the standard timing mechanism.

    Platforms

<B>mytopB> is known to work on:



  * Linux (2.2.x, 2.4.x)
  * FreeBSD (2.2, 3.x, 4.x)
  * Mac OS X
  * BSDI 4.x
  * Solaris 2.x
  * Windows NT 4.x (ActivePerl)



If you find that it works on another platform, please let me know. Given that it is all Perl code, I expect it to be rather portable to Unix and Unix-like systems. Heck, it might even work on Win32 systems.

DESCRIPTION

Help is always welcome in improving this software. Feel free to contact the author (see AUTHOR below) with bug reports, fixes, suggestions, and comments. Additionally BUGS will provide a list of things this software is not able to do yet.

Having said that, here are the details on how it works and what you can do with it.

    The Basics

<B>mytopB> was inspired by the system monitoring tool <B>topB>. I routinely use <B>topB> on Linux, FreeBSD, and Solaris. You are likely to notice features from each of them here.

<B>mytopB> will connect to a MySQL server and periodically run the SHOW PROCESSLIST and SHOW GLOBAL STATUS commands and attempt to summarize the information from them in a useful format.

    The Display

The <B>mytopB> display screen is really broken into two parts. The top 4 lines (header) contain summary information about your MySQL server. For example, you might see something like:

MySQL on localhost (4.0.13-log) up 1+11:13:00 [23:29:11]
Queries: 19.3M qps: 160 Slow: 1.0 Se/In/Up/De(%): 00/80/03/17
qps now: 219 Slow qps: 0.0 Threads: 1 ( 1/ 16) 00/74/00/25
Key Efficiency: 99.3% Bps in/out: 30.5k/162.8 Now in/out: 32.7k/ 3.3k

The first line identifies the hostname of the server (localhost) and the version of MySQL it is running. The right had side shows the uptime of the MySQL server process in days+hours:minutes:seconds format (much like FreeBSD’s top) as well as the current time.

The second line displays the total number of queries the server has processed, the average number of queries per second, the number of slow queries, and the percentage of Select, Insert, Update, and Delete queries.

The third real-time values. First is the number of queries per second, then the number of slow queries, followed by query precentages (like on the previous line).

And the fourth line displays key buffer efficiency (how often keys are read from the buffer rather than disk) and the number of bytes that MySQL has sent and received, both over all and in the last cycle.

You can toggle the header by hitting <B>hB> when running <B>mytopB>.

The second part of the display lists as many threads as can fit on screen. By default they are sorted according to their idle time (least idle first). The display looks like:



    Id     User       Host      Dbase   Time      Cmd Query or State
    --     ----       ----      -----   ----      --- --------------
    61  jzawodn  localhost      music      0    Query show processlist



As you can see, the thread id, username, host from which the user is connecting, database to which the user is connected, number of seconds of idle time, the command the thread is executing, and the query info are all displayed.

Often times the query info is what you are really interested in, so it is good to run <B>mytopB> in an xterm that is wider than the normal 80 columns if possible.

The thread display color-codes the threads if you have installed color support. The current color scheme only works well in a window with a dark (like black) background. The colors are selected according to the Command column of the display:



    Query   -  Yellow
    Sleep   -  White
    Connect -  Green



Those are purely arbitrary and will be customizable in a future release. If they annoy you just start <B>mytopB> with the <B>-nocolorB> flag or adjust your config file appropriately.

    Arguments

<B>mytopB> handles long and short command-line arguments. Not all options have both long and short formats, however. The long arguments can start with one or two dashes ‘-’ or ‘--’. They are shown here with just one.
<B>-uB> or <B>-userB> username Username to use when logging in to the MySQL server. Default: ‘‘root’’.
<B>-pB> or <B>-passB> or <B>-passwordB> password Password to use when logging in to the MySQL server. Default: none.
<B>-hB> or <B>-hostB> hostname[:port] Hostname of the MySQL server. The hostname may be followed by an option port number. Note that the port is specified separate from the host when using a config file. Default: ‘‘localhost’’.
<B>-portB> or <B>-PB> port If you’re running MySQL on a non-standard port, use this to specify the port number. Default: 3306.
<B>-sB> or <B>-delayB> seconds How long between display refreshes. Default: 5
<B>-dB> or <B>-dbB> or <B>-databaseB> database Use if you’d like <B>mytopB> to connect to a specific database by default. Default: ‘‘test’’.
<B>-bB> or <B>-batchB> or <B>-batchmodeB> In batch mode, mytop runs only once, does not clear the screen, and places no limit on the number of lines it will print. This is suitable for running periodically (perhaps from cron) to capture the information into a file for later viewing. You might use batch mode in a CGI script to occasionally display your MySQL server status on the web.

Default: unset.

<B>-SB> or <B>-socketB> /path/to/socket If you’re running <B>mytopB> on the same host as MySQL, you may wish to have it use the MySQL socket directly rather than a standard TCP/IP connection. If you do,just specify one.

Note that specifying a socket will make <B>mytopB> ignore any host and/or port that you might have specified. If the socket does not exist (or the file specified is not a socket), this option will be ignored and <B>mytopB> will use the hostname and port number instead.

Default: none.

<B>-headerB> or <B>-noheaderB> Sepcify if you want the header to display or not. You can toggle this with the <B>hB> key while <B>mytopB> is running.

Default: header.

<B>-colorB> or <B>-nocolorB> Specify if you want a color display. This has no effect if you don’t have color support available.

Default: If you have color support, <B>mytopB> will try color unless you tell it not to.

<B>-iB> or <B>-idleB> or <B>-noidleB> Specify if you want idle (sleeping) threads to appear in the list. If sleeping threads are omitted, the default sorting order is reversed so that the longest running queries appear at the top of the list.

Default: idle.

<B>-promptB> or <B>-nopromptB> Specify if you want to be prompted to type in your database password. This provides a little bit more security since it not only prevents the password from viewable in a process list, but also doesn’t require the password to be stored in plain text in your ~/.mytop config file. You will <B>onlyB> be prompted if a password has not been specified in your config file or through another command line option.

Default: noprompt.

<B>-resolveB> If you have skip-resolve set on MySQL (to keep it from doing a reverse DNS lookup on each inbound connection), mytop can replace IP addresses with hostnames but toggling this option.

Default: noresolve

Command-line arguments will always take precedence over config file options. That happens because the config file is read BEFORE the command-line arguments are applied.

    Config File

Instead of always using bulky command-line parameters, you can also use a config file in your home directory (~/.mytop). If present, <B>mytopB> will read it automatically. It is read before any of your command-line arguments are processed, so your command-line arguments will override directives in the config file.

Here is a sample config file ~/.mytop which implements the defaults described above.



  user=root
  pass=
  host=localhost
  db=test
  delay=5
  port=3306
  socket=
  batchmode=0
  header=1
  color=1
  idle=1



Using a config file will help to ensure that your database password isn’t visible to users on the command-line. Just make sure that the permissions on ~/.mytop are such that others cannot read it (unless you want them to, of course).

You may have white space on either side of the = in lines of the config file.

    Shortcut Keys

The following keys perform various actions while <B>mytopB> is running. Those which have not been implemented are listed as such. They are included to give the user idea of what is coming.
<B>?B> Display help.
<B>cB> Show command counters based on the Com_* values in SHOW GLOBAL STATUS. This is a new feature. Feedback welcome.
<B>dB> Show only threads connected to a particular database.
<B>fB> Given a thread id, display the entire query that thread was (and still may be) running.
<B>FB> Disable all filtering (host, user, and db).
<B>hB> Only show queries from a particular host.
<B>HB> Toggle the header display. You can also specify either header=0 or header=1 in your config file to set the default behavior.
<B>iB> Toggle the display of idle (sleeping) threads. If sleeping threads are filtered, the default sorting order is reversed so that the longest running queries appear at the top of the list.
<B>IB> Switch to InnoDB Status mode. The output of SHOW INNODB STATUS will be displayed every cycle. In a future version, this may actually summarize that data rather than producing raw output.
<B>kB> Kill a thread.
<B>mB> Toggle modes. Currently this switches from ‘top’ mode to ‘qps’ (Queries Per Second Mode). In this mode, mytop will write out one integer per second. The number written reflects the number of queries executed by the server in the previous one second interval.

More modes may be added in the future.

<B>oB> Reverse the default sort order.
<B>pB> Pause display.
<B>qB> Quit <B>mytopB>
<B>rB> Reset the server’s status counters via a FLUSH STATUS command.
<B>sB> Change the sleep time (number of seconds between display refreshes).
<B>uB> Show only threads owned by a giver user.
The <B>sB> key has a command-line counterpart: <B>-sB>.

The <B>hB> key has two command-line counterparts: <B>-headerB> and <B>-noheaderB>.

BUGS

This is more of a BUGS + WishList.

Some performance information is not available when talking to a version 3.22.x MySQL server. Additional information (about threads mostly) was added to the output of SHOW STATUS in MySQL 3.23.x and <B>mytopB> makes use of it. If the information is not available, you will simply see zeros where the real numbers should be.

Simply running this program will increase your overall counters (such as the number of queries run). But you may or may not view that as a bug.

<B>mytopB> consumes too much CPU time when running (verified on older versions of Linux and FreeBSD). It’s likely a problem related to Term::ReadKey. I haven’t had time to investigate yet, so <B>mytopB> now automatically lowers its priority when you run it. You may also think about running <B>mytopB> on another workstation instead of your database server. However, mytop on Solaris does <B>notB> have this problem. Newer versions of Linux and FreeBSD seem to have fixed this.

You can’t specify the maximum number of threads to list. If you have many threads and a tall xterm, <B>mytopB> will always try to display as many as it can fit.

The size of most of the columns in the display has a small maximum width. If you have fairly long database/user/host names the display may appear odd. I have no good idea as to how best to deal with that yet. Suggestions are welcome.

It’d be nice if you could just add <B>mytopB> configuration directives in your my.cnf file instead of having a separate config file.

You should be able to specify the columns you’d like to see in the display and the order in which they appear. If you only have one username that connects to your database, it’s probably not worth having the User column appear, for example.

AUTHOR

mytop was developed and is maintained by Jeremy D. Zawodny (Jeremy@Zawodny.com).

If you wish to e-mail me regarding this software, <B>PLEASEB> subscribe to the <B>mytopB> mailing list. See the <B>mytopB> homepage for details.

DISCLAIMER

While I use this software in my job at Yahoo!, I am solely responsible for it. Yahoo! does not necessarily support this software in any way. It is merely a personal idea which happened to be very useful in my job.

RECRUITING

If you hack Perl and grok MySQL, come work at Yahoo! Contact me for details. Or just send me your resume. Er, unless we just had layoffs, in which case we’re not hiring. :-(

SEE ALSO

Please check the MySQL manual if you’re not sure where some of the output of <B>mytopB> is coming from.

COPYRIGHT

Copyright (C) 2000-2001, Jeremy D. Zawodny.

CREDITS

Fix a bug. Add a feature. See your name here!

Many thanks go to these fine folks:
Sami Ahlroos (sami@avis-net.de) Suggested the idle/noidle stuff.
Jan Willamowius (jan@janhh.shnet.org) Mirnor bug report. Documentation fixes.
Alex Osipov (alex@acky.net) Long command-line options, Unix socket support.
Stephane Enten (tuf@grolier.fr) Suggested batch mode.
Richard Ellerbrock (richarde@eskom.co.za) Bug reports and usability suggestions.
William R. Mattil (wrm@newton.irngtx.tel.gte.com) Bug report about empty passwords not working.
Benjamin Pflugmann (philemon@spin.de) Suggested -P command-line flag as well as other changes.
Justin Mecham <justin@aspect.net> Suggested setting $0 to ‘mytop’.
Thorsten Kunz <thorsten.kunz@de.tiscali.com> Provided a fix for cases when we try remove the domain name from the display even if it is actually an IP address.
Sasha Pachev <sasha@mysql.com> Provided the idea of real-time queries per second in the main display.
Paul DuBois <paul@snake.net> Pointed out some option-handling bugs.
Mike Wexler <mwexler@tias.com> Suggested that we don’t mangle (normalize) whitespace in query info by default.
Mark Zweifel <markez@yahoo-inc.com> Make the --idle command-line argument negatable.
Axel Schwenke <schwenke@jobpilot.de> Noticed the inccorect formula for query cache hit percentages in version 1.2.
Steven Roussey <sroussey@network54.com> Supplied a patch to help filter binary junk in queries so that terminals don’t freak out.
jon r. luini <falcon@chime.com> Supplied a patch that formed the basis for -prompt support. Sean Leach <sleach@wiggum.com> submitted a similar patch.
Yogish Baliga <baliga@yahoo-inc.com> Supplied a patch that formed the basis for -resolve support.
Per Andreas Buer <perbu@linpro.no> Supplied an excellent patch to tidy up the top display. This includes showing most values in short form, such as 10k rather than 10000.
See the Changes file on the <B>mytopB> distribution page for more details on what has changed.

LICENSE

<B>mytopB> is licensed under the GNU General Public License version 2. For the full license information, please visit http://www.gnu.org/copyleft/gpl.html
Search for    or go to Top of page |  Section 1 |  Main Index


perl v5.20.3 MYTOP (1) 2016-04-03

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.