Xaprb

Stay curious!

Archive for the ‘mext’ tag

Using mext to format saved mysqladmin output nicely

with one comment

I wrote a while ago about how mext works — it runs “mysqladmin extended-status” and formats it nicely. But what if you want to use it to format saved output that you’ve put into a file? It’s actually very easy. You can tell it what command-line to run to generate its input. By default you are probably going to tell it to run “mysqladmin ext -ri10″ or something like that, but you can just as easily make it run “cat my-saved-output”.

Let’s see how this can be useful. Imagine I have a server that stalls every now and then, and I’ve set up mk-loadavg to watch for this and capture information about system activity with a script that contains

$ mysqladmin ext -c 30 -i1 > mysqladmin-output.txt

That’ll gather 30 samples one second apart. Now I’ll format it:

$ wget -q http://www.maatkit.org/mext
$ sh mext -r -- cat mysqladmin-output.txt | less -S

I’m piping the output into less -S so that I can see unwrapped output. 30 samples of mysql status variables are going to be aligned in columns next to each other, so without the -S flag I’ll probably see something unhelpful.

If you have a hard time visualizing the above, go ahead and run the commands! It’ll take only a minute, and it’ll make a lot more sense to you then. This is a really useful way to summarize and understand what is going on (or has gone on) inside your MySQL server.

Written by Xaprb

October 13th, 2009 at 9:00 pm

Posted in SQL

Tagged with

A tweak to column alignment for the mext script

without comments

I tweaked the mext script so it auto-detects the necessary column widths for each sample.

Get mext here.

Written by Xaprb

June 5th, 2009 at 1:50 pm

Posted in Coding, SQL, Tools

Tagged with

Formatting mysqladmin extended-status nicely

with 3 comments

I always say that the ultimate MySQL tuning script is an expert human. To that end, I generally try to build tools that help a human be more productive with the raw information from MySQL. One of the things we look at during a performance audit is the MySQL status counters. It’s useful to look at a) absolute values and b) several incremental snapshots. I’ve written a small shell script called “mext” that can make this a little easier.

It looks like this:

baron@kanga:~$ mext -- mysqladmin ext -ri1 -c3
Aborted_clients                               1      0      0
Aborted_connects                              0      0      0
Binlog_cache_disk_use                         0      0      0
Binlog_cache_use                              0      0      0
Bytes_received                             1167     35     35
Bytes_sent                                38926   6337   6337
....

This isn’t an original idea. Ryan Lowe made a Perl version of this first. I used his version for a while, but after working on a few machines that didn’t have the necessary Perl libraries (maybe one of them didn’t even have Perl, I forget) I decided to do it in shell.

There’s an added feature. It’ll do incremental/differential/relative output for you. The mysqladmin that ships with MySQL 5.1 has a bug that stops it from iterating with -r. So the script I wrote can accept a -r option, which can then be left off the arguments to mysqladmin:

baron@kanga:~$ mext -r -- mysqladmin ext -i1 -c3

It’s kind of a generic tool that you could use with other things besides mysqladmin, but it’s also kind of tweaked for that purpose. You can get mext here.

Written by Xaprb

April 11th, 2009 at 11:41 am

Posted in Coding, SQL, Tools

Tagged with , ,