mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 05:00:45 +00:00
pt-ms & pt-stalk: Enable the standard mysql options
This commit is contained in:
@@ -347,14 +347,14 @@ _parse_command_line() {
|
||||
|
||||
if [ "$next_opt_is_val" ]; then
|
||||
next_opt_is_val=""
|
||||
if [ $# -eq 0 ] || [ $(expr "$opt" : "-") -eq 1 ]; then
|
||||
if [ $# -eq 0 ] || [ $(expr "$opt" : "\-") -eq 1 ]; then
|
||||
option_error "$real_opt requires a $required_arg argument"
|
||||
continue
|
||||
fi
|
||||
val="$opt"
|
||||
opt_is_ok=1
|
||||
else
|
||||
if [ $(expr "$opt" : "-") -eq 0 ]; then
|
||||
if [ $(expr "$opt" : "\-") -eq 0 ]; then
|
||||
if [ -z "$ARGV" ]; then
|
||||
ARGV="$opt"
|
||||
else
|
||||
@@ -450,6 +450,46 @@ size_to_bytes() {
|
||||
# End parse_options package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# mysql_options package
|
||||
# This package is a copy without comments from the original. The original
|
||||
# with comments and its test file can be found in the Bazaar repository at,
|
||||
# lib/bash/mysql_options.sh
|
||||
# t/lib/bash/mysql_options.sh
|
||||
# See https://launchpad.net/percona-toolkit for more information.
|
||||
# ###########################################################################
|
||||
|
||||
|
||||
set -u
|
||||
|
||||
mysql_options() {
|
||||
local MYSQL_ARGS=""
|
||||
if [ -n "$OPT_DEFAULTS_FILE" ]; then
|
||||
MYSQL_ARGS="--defaults-file=$OPT_DEFAULTS_FILE"
|
||||
fi
|
||||
if [ -n "$OPT_PORT" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --port=$OPT_PORT"
|
||||
fi
|
||||
if [ -n "$OPT_SOCKET" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --socket=$OPT_SOCKET"
|
||||
fi
|
||||
if [ -n "$OPT_HOST" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --host=$OPT_HOST"
|
||||
fi
|
||||
if [ -n "$OPT_USER" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --user='$OPT_USER'"
|
||||
fi
|
||||
if [ -n "$OPT_PASSWORD" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --password='$OPT_PASSWORD'"
|
||||
fi
|
||||
|
||||
echo $MYSQL_ARGS
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
# End mysql_options package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# tmpdir package
|
||||
# This package is a copy without comments from the original. The original
|
||||
@@ -788,7 +828,6 @@ collect_mysqld_instances () {
|
||||
echo "internal::oom_of_$pid $oom" >> "$variables_file"
|
||||
done
|
||||
|
||||
pids="$pids"
|
||||
pids="$(echo $pids | sed -e 's/ /,/g')"
|
||||
ps ww -p "$pids" 2>/dev/null
|
||||
else
|
||||
@@ -930,8 +969,13 @@ get_mysqldump_args () {
|
||||
collect_mysqld_executables () {
|
||||
local mysqld_instances="$1"
|
||||
|
||||
local ps_opt="cmd="
|
||||
if [ "$(uname -s)" = "Darwin" ]; then
|
||||
ps_opt="command="
|
||||
fi
|
||||
|
||||
for pid in $( grep '/mysqld' "$mysqld_instances" | awk '/^.*[0-9]/{print $1}' ); do
|
||||
ps -o cmd -p $pid | sed -e 's/^\(.*mysqld\) .*/\1/' | grep -v '^CMD$'
|
||||
ps -o $ps_opt -p $pid | sed -e 's/^\(.*mysqld\) .*/\1/'
|
||||
done | sort -u
|
||||
}
|
||||
|
||||
@@ -2185,7 +2229,7 @@ report_mysql_summary () {
|
||||
|| [ -e "$dir/mysqldump" -a -s "$dir/mysqldump" ]; then
|
||||
reply="y"
|
||||
elif [ -t 0 -a -t 1 ]; then
|
||||
echo -n "Would you like to mysqldump -d the schema and analyze it? y/n "
|
||||
printf "Would you like to mysqldump -d the schema and analyze it? y/n "
|
||||
read reply
|
||||
reply=${reply:-n}
|
||||
fi
|
||||
@@ -2193,7 +2237,7 @@ report_mysql_summary () {
|
||||
if [ -z "${OPT_DATABASES}" ] && [ -z "$OPT_READ_SAMPLES" ] \
|
||||
&& [ ! -e "$dir/mysqldump" ]; then
|
||||
echo "There are ${num_dbs} databases. Would you like to dump all, or just one?"
|
||||
echo -n "Type the name of the database, or press Enter to dump all of them. "
|
||||
printf "Type the name of the database, or press Enter to dump all of them. "
|
||||
local dbtodump=""
|
||||
read dbtodump
|
||||
local trg_arg="$( get_mysqldump_args "$dir/mysql-variables" )"
|
||||
@@ -2320,6 +2364,7 @@ report_mysql_summary () {
|
||||
|
||||
section "Configuration File"
|
||||
local cnf_file="$(get_var "pt-summary-internal-Config_File_path" "$dir/mysql-variables")"
|
||||
|
||||
if [ -n "${cnf_file}" ]; then
|
||||
name_val "Config File" "${cnf_file}"
|
||||
pretty_print_cnf_file "$dir/mysql-config-file"
|
||||
@@ -2376,6 +2421,14 @@ main() {
|
||||
# Prepending SIG to these doesn't work with NetBSD's sh
|
||||
trap sigtrap HUP INT TERM
|
||||
|
||||
local MYSQL_ARGS="$(mysql_options)"
|
||||
EXT_ARGV="$EXT_ARGV $MYSQL_ARGS"
|
||||
|
||||
# Check if mysql and mysqldump are there, otherwise bail out early.
|
||||
# But don't if they passed in --read-samples, since we don't need
|
||||
# a connection then.
|
||||
[ "$OPT_READ_SAMPLES" ] || check_mysql
|
||||
|
||||
local RAN_WITH="--sleep=$OPT_SLEEP --databases=$OPT_DATABASES --save-samples=$OPT_SAVE_SAMPLES"
|
||||
|
||||
_d "Starting $0 $RAN_WITH"
|
||||
@@ -2442,11 +2495,6 @@ if [ "${0##*/}" = "$TOOL" ] \
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if mysql and mysqldump are there, otherwise bail out early.
|
||||
# But don't if they passed in --read-samples, since we don't need
|
||||
# a connection then.
|
||||
[ "$OPT_READ_SAMPLES" ] || check_mysql
|
||||
|
||||
main "${@:-""}"
|
||||
fi
|
||||
|
||||
@@ -2498,7 +2546,7 @@ and other scripting languages.
|
||||
To use, simply execute it. Optionally add a double dash and then the same
|
||||
command-line options you would use to connect to MySQL, such as the following:
|
||||
|
||||
pt-mysql-summary -- --user=root
|
||||
pt-mysql-summary --user=root
|
||||
|
||||
The tool interacts minimally with the server upon which it runs. It assumes
|
||||
that you'll run it on the same server you're inspecting, and therefore it
|
||||
@@ -2923,6 +2971,43 @@ Seconds to sleep when gathering status counters.
|
||||
|
||||
Print tool's version and exit.
|
||||
|
||||
=item --defaults-file
|
||||
|
||||
short form: -F; type: string
|
||||
|
||||
Only read mysql options from the given file. You must give an absolute
|
||||
pathname.
|
||||
|
||||
=item --host
|
||||
|
||||
short form: -h; type: string; default: localhost
|
||||
|
||||
Host to connect to.
|
||||
|
||||
=item --password
|
||||
|
||||
short form: -p; type: string
|
||||
|
||||
Password to use when connecting.
|
||||
|
||||
=item --port
|
||||
|
||||
short form: -P; type: int
|
||||
|
||||
Port number to use for connection.
|
||||
|
||||
=item --socket
|
||||
|
||||
short form: -S; type: string
|
||||
|
||||
Socket file to use for connection.
|
||||
|
||||
=item --user
|
||||
|
||||
short form: -u; type: string
|
||||
|
||||
User for login if not current user.
|
||||
|
||||
=back
|
||||
|
||||
=head1 ENVIRONMENT
|
||||
|
86
bin/pt-stalk
86
bin/pt-stalk
@@ -347,14 +347,14 @@ _parse_command_line() {
|
||||
|
||||
if [ "$next_opt_is_val" ]; then
|
||||
next_opt_is_val=""
|
||||
if [ $# -eq 0 ] || [ $(expr "$opt" : "-") -eq 1 ]; then
|
||||
if [ $# -eq 0 ] || [ $(expr "$opt" : "\-") -eq 1 ]; then
|
||||
option_error "$real_opt requires a $required_arg argument"
|
||||
continue
|
||||
fi
|
||||
val="$opt"
|
||||
opt_is_ok=1
|
||||
else
|
||||
if [ $(expr "$opt" : "-") -eq 0 ]; then
|
||||
if [ $(expr "$opt" : "\-") -eq 0 ]; then
|
||||
if [ -z "$ARGV" ]; then
|
||||
ARGV="$opt"
|
||||
else
|
||||
@@ -450,6 +450,46 @@ size_to_bytes() {
|
||||
# End parse_options package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# mysql_options package
|
||||
# This package is a copy without comments from the original. The original
|
||||
# with comments and its test file can be found in the Bazaar repository at,
|
||||
# lib/bash/mysql_options.sh
|
||||
# t/lib/bash/mysql_options.sh
|
||||
# See https://launchpad.net/percona-toolkit for more information.
|
||||
# ###########################################################################
|
||||
|
||||
|
||||
set -u
|
||||
|
||||
mysql_options() {
|
||||
local MYSQL_ARGS=""
|
||||
if [ -n "$OPT_DEFAULTS_FILE" ]; then
|
||||
MYSQL_ARGS="--defaults-file=$OPT_DEFAULTS_FILE"
|
||||
fi
|
||||
if [ -n "$OPT_PORT" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --port=$OPT_PORT"
|
||||
fi
|
||||
if [ -n "$OPT_SOCKET" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --socket=$OPT_SOCKET"
|
||||
fi
|
||||
if [ -n "$OPT_HOST" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --host=$OPT_HOST"
|
||||
fi
|
||||
if [ -n "$OPT_USER" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --user='$OPT_USER'"
|
||||
fi
|
||||
if [ -n "$OPT_PASSWORD" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --password='$OPT_PASSWORD'"
|
||||
fi
|
||||
|
||||
echo $MYSQL_ARGS
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
# End mysql_options package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# tmpdir package
|
||||
# This package is a copy without comments from the original. The original
|
||||
@@ -1347,6 +1387,9 @@ if [ "${0##*/}" = "$TOOL" ] \
|
||||
exit 0
|
||||
fi
|
||||
|
||||
local MYSQL_ARGS="$(mysql_options)"
|
||||
EXT_ARGV="$EXT_ARGV $MYSQL_ARGS"
|
||||
|
||||
# Check that mysql and mysqladmin are in PATH. If not, we're
|
||||
# already dead in the water, so don't bother with cmd line opts,
|
||||
# just error and exit.
|
||||
@@ -1416,7 +1459,7 @@ pt-stalk - Gather forensic data about MySQL when a problem occurs.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
Usage: pt-stalk [OPTIONS] [-- MYSQL OPTIONS]
|
||||
Usage: pt-stalk [OPTIONS] [-- EXTRA MYSQL OPTIONS]
|
||||
|
||||
pt-stalk watches for a trigger condition to become true, and then collects data
|
||||
to help in diagnosing problems. It is designed to run as a daemon with root
|
||||
@@ -1883,6 +1926,43 @@ want to use a higher verbosity level.
|
||||
|
||||
Print tool's version and exit.
|
||||
|
||||
=item --defaults-file
|
||||
|
||||
short form: -F; type: string
|
||||
|
||||
Only read mysql options from the given file. You must give an absolute
|
||||
pathname.
|
||||
|
||||
=item --host
|
||||
|
||||
short form: -h; type: string; default: localhost
|
||||
|
||||
Host to connect to.
|
||||
|
||||
=item --password
|
||||
|
||||
short form: -p; type: string
|
||||
|
||||
Password to use when connecting.
|
||||
|
||||
=item --port
|
||||
|
||||
short form: -P; type: int
|
||||
|
||||
Port number to use for connection.
|
||||
|
||||
=item --socket
|
||||
|
||||
short form: -S; type: string
|
||||
|
||||
Socket file to use for connection.
|
||||
|
||||
=item --user
|
||||
|
||||
short form: -u; type: string
|
||||
|
||||
User for login if not current user.
|
||||
|
||||
=back
|
||||
|
||||
=head1 ENVIRONMENT
|
||||
|
@@ -354,14 +354,14 @@ _parse_command_line() {
|
||||
|
||||
if [ "$next_opt_is_val" ]; then
|
||||
next_opt_is_val=""
|
||||
if [ $# -eq 0 ] || [ $(expr "$opt" : "-") -eq 1 ]; then
|
||||
if [ $# -eq 0 ] || [ $(expr "$opt" : "\-") -eq 1 ]; then
|
||||
option_error "$real_opt requires a $required_arg argument"
|
||||
continue
|
||||
fi
|
||||
val="$opt"
|
||||
opt_is_ok=1
|
||||
else
|
||||
if [ $(expr "$opt" : "-") -eq 0 ]; then
|
||||
if [ $(expr "$opt" : "\-") -eq 0 ]; then
|
||||
if [ -z "$ARGV" ]; then
|
||||
ARGV="$opt"
|
||||
else
|
||||
|
@@ -43,7 +43,6 @@ collect_mysqld_instances () {
|
||||
echo "internal::oom_of_$pid $oom" >> "$variables_file"
|
||||
done
|
||||
|
||||
pids="$pids"
|
||||
pids="$(echo $pids | sed -e 's/ /,/g')"
|
||||
ps ww -p "$pids" 2>/dev/null
|
||||
else
|
||||
@@ -201,8 +200,13 @@ get_mysqldump_args () {
|
||||
collect_mysqld_executables () {
|
||||
local mysqld_instances="$1"
|
||||
|
||||
local ps_opt="cmd="
|
||||
if [ "$(uname -s)" = "Darwin" ]; then
|
||||
ps_opt="command="
|
||||
fi
|
||||
|
||||
for pid in $( grep '/mysqld' "$mysqld_instances" | awk '/^.*[0-9]/{print $1}' ); do
|
||||
ps -o cmd -p $pid | sed -e 's/^\(.*mysqld\) .*/\1/' | grep -v '^CMD$'
|
||||
ps -o $ps_opt -p $pid | sed -e 's/^\(.*mysqld\) .*/\1/'
|
||||
done | sort -u
|
||||
}
|
||||
|
||||
|
52
lib/bash/mysql_options.sh
Normal file
52
lib/bash/mysql_options.sh
Normal file
@@ -0,0 +1,52 @@
|
||||
# This program is copyright 2011 Percona Inc.
|
||||
# Feedback and improvements are welcome.
|
||||
#
|
||||
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
#
|
||||
# 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, version 2; OR the Perl Artistic License. On UNIX and similar
|
||||
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
|
||||
# licenses.
|
||||
#
|
||||
# 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.
|
||||
# ###########################################################################
|
||||
# mysql_options package
|
||||
# ###########################################################################
|
||||
|
||||
# Package: mysql_options
|
||||
# Handle --defaults-file & related options
|
||||
|
||||
set -u
|
||||
|
||||
mysql_options() {
|
||||
local MYSQL_ARGS=""
|
||||
if [ -n "$OPT_DEFAULTS_FILE" ]; then
|
||||
MYSQL_ARGS="--defaults-file=$OPT_DEFAULTS_FILE"
|
||||
fi
|
||||
if [ -n "$OPT_PORT" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --port=$OPT_PORT"
|
||||
fi
|
||||
if [ -n "$OPT_SOCKET" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --socket=$OPT_SOCKET"
|
||||
fi
|
||||
if [ -n "$OPT_HOST" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --host=$OPT_HOST"
|
||||
fi
|
||||
if [ -n "$OPT_USER" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --user='$OPT_USER'"
|
||||
fi
|
||||
if [ -n "$OPT_PASSWORD" ]; then
|
||||
MYSQL_ARGS="$MYSQL_ARGS --password='$OPT_PASSWORD'"
|
||||
fi
|
||||
|
||||
echo $MYSQL_ARGS
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
# End mysql_options package
|
||||
# ###########################################################################
|
@@ -398,7 +398,7 @@ _parse_command_line() {
|
||||
|
||||
if [ "$next_opt_is_val" ]; then
|
||||
next_opt_is_val=""
|
||||
if [ $# -eq 0 ] || [ $(expr "$opt" : "-") -eq 1 ]; then
|
||||
if [ $# -eq 0 ] || [ $(expr "$opt" : "\-") -eq 1 ]; then
|
||||
option_error "$real_opt requires a $required_arg argument"
|
||||
continue
|
||||
fi
|
||||
@@ -406,7 +406,7 @@ _parse_command_line() {
|
||||
opt_is_ok=1
|
||||
else
|
||||
# If option does not begin with a hyphen (-), it's a filename, etc.
|
||||
if [ $(expr "$opt" : "-") -eq 0 ]; then
|
||||
if [ $(expr "$opt" : "\-") -eq 0 ]; then
|
||||
if [ -z "$ARGV" ]; then
|
||||
ARGV="$opt"
|
||||
else
|
||||
|
@@ -1489,6 +1489,7 @@ report_mysql_summary () {
|
||||
# ########################################################################
|
||||
section "Configuration File"
|
||||
local cnf_file="$(get_var "pt-summary-internal-Config_File_path" "$dir/mysql-variables")"
|
||||
|
||||
if [ -n "${cnf_file}" ]; then
|
||||
name_val "Config File" "${cnf_file}"
|
||||
pretty_print_cnf_file "$dir/mysql-config-file"
|
||||
|
34
t/lib/bash/mysql_options.sh
Normal file
34
t/lib/bash/mysql_options.sh
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plan 3
|
||||
|
||||
TMPFILE="$TEST_PT_TMPDIR/parse-opts-output"
|
||||
TOOL="pt-mysql-summary"
|
||||
PT_TMPDIR="$TEST_PT_TMPDIR"
|
||||
|
||||
source "$LIB_DIR/log_warn_die.sh"
|
||||
source "$LIB_DIR/parse_options.sh"
|
||||
source "$LIB_DIR/mysql_options.sh"
|
||||
|
||||
cnf="/tmp/12345/my.sandbox.cnf"
|
||||
|
||||
parse_options "$PERCONA_TOOLKIT_BRANCH/bin/pt-mysql-summary" --defaults-file $cnf
|
||||
is "$OPT_DEFAULTS_FILE" "$cnf" "--defaults-file works"
|
||||
|
||||
# ############################################################################
|
||||
# --host's default works
|
||||
# ############################################################################
|
||||
|
||||
parse_options "$PERCONA_TOOLKIT_BRANCH/bin/pt-mysql-summary"
|
||||
is "$OPT_HOST" "localhost" "--host has default: localhost"
|
||||
|
||||
# ############################################################################
|
||||
# Short forms work
|
||||
# ############################################################################
|
||||
|
||||
parse_options "$PERCONA_TOOLKIT_BRANCH/bin/pt-mysql-summary" -F $cnf
|
||||
is "$OPT_DEFAULTS_FILE" "$cnf" "-F works"
|
||||
|
||||
# ############################################################################
|
||||
# Done
|
||||
# ############################################################################
|
1
t/lib/bash/mysql_options.t
Symbolic link
1
t/lib/bash/mysql_options.t
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../util/test-bash-functions
|
Reference in New Issue
Block a user