pt-ms & pt-stalk: Enable the standard mysql options

This commit is contained in:
Brian Fraser
2013-02-25 11:21:46 -03:00
parent c9aa9e8cbd
commit 9e2ce2197f
9 changed files with 279 additions and 22 deletions

View File

@@ -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,10 +2971,47 @@ 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
This tool does not use any environment variables.
=head1 SYSTEM REQUIREMENTS