#!/usr/bin/perl eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0; # not running under some shell $VERSION = "0.6.6"; $RELEASE = "20070304"; # # $Id: mkill.PL,v 1.6 2004/09/12 21:19:12 mdprewitt Exp $ # # mkill - Kill longs running queries # Copyright (C) 2002 Marc Prewitt/Chelsea Networks # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 of the License, or (at your # option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # =head1 NAME B - Kills slow queries =head1 SYNOPSIS mkill [--host={mysql_host}] [--dbuser={mysql_user}] [--password={mysqluser_pw}] [--filter-user={regex}] [--filter-host={regex}] [--filter-db={regex}] [--filter-command={regex}] [--filter-state={regex}] [--filter-info={{regex}}] [--user={user}] [--slow={seconds}] [--daemonize] [--test] mkill --help mkill --version =head1 DESCRIPTION This is an alpha version of this program. Please let me know what you think and what additional features would be nice. Future version will most likely perform the same but have different output. One idea i've been thinking about is letting you specify filters which short perl snippets instead of just regexes. This program kills long running queries based on several criteria including query time, host, user, database, state, and query content. The following keys are active while mkill is running: q - quit A log of killed queries is sent to STDERR, watched queries are sent to STDOUT. A typical command line would be: mkill -sl 180 -fi 'select.*from bad_table' > /var/log/mkill.out 2> /var/log/mkill.kill =head1 OPTIONS All options can be abbreviated by their shortest unique abbreviation. =over 4 =item -?, --help Show the help screen and exit. =item -t, --test Show what would be done but don't actually kill anything. Good for testing your filter expressions. =item -v, --version Show the version number and exit. =item -h {mysql_host}, --host={mysql_host} By default, the mysqld on localhost is monitored. Specify an alternate host with this option. =item -dbu {mysql_user}, --dbuser={mysql_user} By default, the user 'mysqltop' is used to connect to the database. Specify an alternate user with this option. =item -p {mysqluser_pw}, --password={mysqluser_pw} By default, there is no password associated with the mysqltop user, specify a password with this option. =item -sl {seconds}, --slow={seconds} The number of seconds before a slow query is killed. The default is 180 seconds. =back =head1 FILTER OPTIONS =over 4 =item -u {user}, --user={user} Kill only threads owned by this user. =item -fu {regex_pattern}, --filter-user={regex_pattern} =item -fh {regex_pattern}, --filter-host={regex_pattern} =item -fd {regex_pattern}, --filter-db={regex_pattern} =item -fs {regex_pattern}, --filter-state={regex_pattern} =item -fc {regex_pattern}, --filter-command={regex_pattern} =item -fi {regex_pattern}, --filter-info={regex_pattern} Filter the queries based on the B provided. The B is a perl regular expression. The regular expression match is done with case insensitivity. For example, to only kill B