Blog

mprofile を Python に移植した

http://developer.cybozu.co.jp/archives/kazuho/2009/07/mysql-539d.html

SHOW FULL PROCESSLIST を 0.1 秒ごとに1000回取得し、その結果を眺めるという kazuho さんが書いた mprofile という便利スクリプトがあります。

これは Perl で書かれていて、それはそれでいいんですが Python で書きたいというアレがあったので Python で書きなおした。 (お察しください)

https://github.com/tokuhirom/mprofile-python

# Python port of mprofile(MySQL profiler)

This is a port of mprofile(written in perl).

Original repo is here: https://github.com/kazuho/mprofile

## DEPENDENCIES

  * Python 2.7+
  * MySQL-python

## INSTALL

On CentOS:

    % sudo yum install MySQL-python

Other systems:

    % sudo pip install MySQL-python

## SYNOPSIS

By default, mpdump script connect to localhost database by root user without password.
If you to modify the connection options, you need to edit the script.

First, take a dump file. This script runs 'SHOW FULL PROCESSLIST' periodically.

    % ./mpdump > mpdump.txt

Then, replace variable parameters by 'mpfilter' command. And collect the result by mpreport command.

    % mpfilter < mpdump.txt | mpreport | head -100

For more details, here is a kazuho-san's article(In Japanese): http://developer.cybozu.co.jp/archives/kazuho/2009/07/mysql-539d.html

## MOTIVATION

I don't want to install DBI/DBD::mysql and dependent modules for the server.

## FAQ

### How do I install these scripts to servers, that protected by firewall?

Clone this repo and run following command on your OSX machine.

    > shar mp* | pbcopy

Then, paste it on the terminal, that connected to remote server.

## LICENSE

Python version's copyright notice is here:

    The MIT License (MIT)
    Copyright © 2015 Tokuhiro Matsuno, http://64p.org/ <[email protected]>

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the “Software”), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.

Original mprofile's copyright notice is here:

    Copyright (C) 2009 Cybozu Labs, Inc.
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:

        * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

        * Redistributions in binary form must reproduce the above
    copyright notice, this list of conditions and the following disclaimer
    in the documentation and/or other materials provided with the
    distribution.

        * The names of its contributors may not be used to endorse or
    promote products derived from this software without specific prior
    written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.