From 9e2ce2197f7de70913050c4190df204f3a9737cf Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Mon, 25 Feb 2013 11:21:46 -0300 Subject: [PATCH 1/6] pt-ms & pt-stalk: Enable the standard mysql options --- bin/pt-mysql-summary | 111 +++++++++++++++++++++++++++++---- bin/pt-stalk | 86 ++++++++++++++++++++++++- bin/pt-summary | 4 +- lib/bash/collect_mysql_info.sh | 8 ++- lib/bash/mysql_options.sh | 52 +++++++++++++++ lib/bash/parse_options.sh | 4 +- lib/bash/report_mysql_info.sh | 1 + t/lib/bash/mysql_options.sh | 34 ++++++++++ t/lib/bash/mysql_options.t | 1 + 9 files changed, 279 insertions(+), 22 deletions(-) create mode 100644 lib/bash/mysql_options.sh create mode 100644 t/lib/bash/mysql_options.sh create mode 120000 t/lib/bash/mysql_options.t diff --git a/bin/pt-mysql-summary b/bin/pt-mysql-summary index 8691b59f..ad829b41 100755 --- a/bin/pt-mysql-summary +++ b/bin/pt-mysql-summary @@ -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 diff --git a/bin/pt-stalk b/bin/pt-stalk index 8adbd5bc..859debae 100755 --- a/bin/pt-stalk +++ b/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 diff --git a/bin/pt-summary b/bin/pt-summary index 32e864b7..32a8b7db 100755 --- a/bin/pt-summary +++ b/bin/pt-summary @@ -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 diff --git a/lib/bash/collect_mysql_info.sh b/lib/bash/collect_mysql_info.sh index df4bddcd..e99295f4 100644 --- a/lib/bash/collect_mysql_info.sh +++ b/lib/bash/collect_mysql_info.sh @@ -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 } diff --git a/lib/bash/mysql_options.sh b/lib/bash/mysql_options.sh new file mode 100644 index 00000000..755b348e --- /dev/null +++ b/lib/bash/mysql_options.sh @@ -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 +# ########################################################################### diff --git a/lib/bash/parse_options.sh b/lib/bash/parse_options.sh index e479ad66..c2dbcce5 100644 --- a/lib/bash/parse_options.sh +++ b/lib/bash/parse_options.sh @@ -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 diff --git a/lib/bash/report_mysql_info.sh b/lib/bash/report_mysql_info.sh index eb3749c6..09fee8db 100644 --- a/lib/bash/report_mysql_info.sh +++ b/lib/bash/report_mysql_info.sh @@ -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" diff --git a/t/lib/bash/mysql_options.sh b/t/lib/bash/mysql_options.sh new file mode 100644 index 00000000..2d966ce7 --- /dev/null +++ b/t/lib/bash/mysql_options.sh @@ -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 +# ############################################################################ diff --git a/t/lib/bash/mysql_options.t b/t/lib/bash/mysql_options.t new file mode 120000 index 00000000..edb04c13 --- /dev/null +++ b/t/lib/bash/mysql_options.t @@ -0,0 +1 @@ +../../../util/test-bash-functions \ No newline at end of file From ebd83f5ba4053189d0fc6904cfcdceaf343eb14a Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Tue, 5 Mar 2013 11:32:21 -0300 Subject: [PATCH 2/6] Minor fixes for compat --- bin/pt-stalk | 6 +++--- lib/bash/mysql_options.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/pt-stalk b/bin/pt-stalk index 859debae..2f84c500 100755 --- a/bin/pt-stalk +++ b/bin/pt-stalk @@ -477,10 +477,10 @@ mysql_options() { MYSQL_ARGS="$MYSQL_ARGS --host=$OPT_HOST" fi if [ -n "$OPT_USER" ]; then - MYSQL_ARGS="$MYSQL_ARGS --user='$OPT_USER'" + MYSQL_ARGS="$MYSQL_ARGS --user=$OPT_USER" fi if [ -n "$OPT_PASSWORD" ]; then - MYSQL_ARGS="$MYSQL_ARGS --password='$OPT_PASSWORD'" + MYSQL_ARGS="$MYSQL_ARGS --password=$OPT_PASSWORD" fi echo $MYSQL_ARGS @@ -1387,7 +1387,7 @@ if [ "${0##*/}" = "$TOOL" ] \ exit 0 fi - local MYSQL_ARGS="$(mysql_options)" + MYSQL_ARGS="$(mysql_options)" EXT_ARGV="$EXT_ARGV $MYSQL_ARGS" # Check that mysql and mysqladmin are in PATH. If not, we're diff --git a/lib/bash/mysql_options.sh b/lib/bash/mysql_options.sh index 755b348e..a3db9ffd 100644 --- a/lib/bash/mysql_options.sh +++ b/lib/bash/mysql_options.sh @@ -38,10 +38,10 @@ mysql_options() { MYSQL_ARGS="$MYSQL_ARGS --host=$OPT_HOST" fi if [ -n "$OPT_USER" ]; then - MYSQL_ARGS="$MYSQL_ARGS --user='$OPT_USER'" + MYSQL_ARGS="$MYSQL_ARGS --user=$OPT_USER" fi if [ -n "$OPT_PASSWORD" ]; then - MYSQL_ARGS="$MYSQL_ARGS --password='$OPT_PASSWORD'" + MYSQL_ARGS="$MYSQL_ARGS --password=$OPT_PASSWORD" fi echo $MYSQL_ARGS From 0efad73f3e4450f268c4eb7a18f25bd79e43ddde Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Wed, 6 Mar 2013 12:52:17 -0300 Subject: [PATCH 3/6] Rearrange mysql options so that --defaults-file is always first, and remove default: localhost from pt-ms and pt-stalk, since parse_options.sh deals with defaults + config files for mysql options poorly --- bin/pt-mysql-summary | 4 ++-- bin/pt-stalk | 19 +++++++++++++++++-- lib/bash/mysql_options.sh | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/bin/pt-mysql-summary b/bin/pt-mysql-summary index ad829b41..4233722d 100755 --- a/bin/pt-mysql-summary +++ b/bin/pt-mysql-summary @@ -2422,7 +2422,7 @@ main() { trap sigtrap HUP INT TERM local MYSQL_ARGS="$(mysql_options)" - EXT_ARGV="$EXT_ARGV $MYSQL_ARGS" + EXT_ARGV="$(arrange_mysql_options "$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 @@ -2980,7 +2980,7 @@ pathname. =item --host -short form: -h; type: string; default: localhost +short form: -h; type: string Host to connect to. diff --git a/bin/pt-stalk b/bin/pt-stalk index 2f84c500..6d916814 100755 --- a/bin/pt-stalk +++ b/bin/pt-stalk @@ -486,6 +486,21 @@ mysql_options() { echo $MYSQL_ARGS } +arrange_mysql_options() { + local opts="$1" + + local rearranged="" + for opt in $opts; do + if [ "$(echo $opt | awk -F= '{print $1}')" = "--defaults-file" ]; then + rearranged="$opt $rearranged" + else + rearranged="$rearranged $opt" + fi + done + + echo "$rearranged" +} + # ########################################################################### # End mysql_options package # ########################################################################### @@ -1388,7 +1403,7 @@ if [ "${0##*/}" = "$TOOL" ] \ fi MYSQL_ARGS="$(mysql_options)" - EXT_ARGV="$EXT_ARGV $MYSQL_ARGS" + EXT_ARGV="$(arrange_mysql_options "$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, @@ -1935,7 +1950,7 @@ pathname. =item --host -short form: -h; type: string; default: localhost +short form: -h; type: string Host to connect to. diff --git a/lib/bash/mysql_options.sh b/lib/bash/mysql_options.sh index a3db9ffd..c248bd1f 100644 --- a/lib/bash/mysql_options.sh +++ b/lib/bash/mysql_options.sh @@ -47,6 +47,22 @@ mysql_options() { echo $MYSQL_ARGS } +# This basically makes sure that --defaults-file comes first +arrange_mysql_options() { + local opts="$1" + + local rearranged="" + for opt in $opts; do + if [ "$(echo $opt | awk -F= '{print $1}')" = "--defaults-file" ]; then + rearranged="$opt $rearranged" + else + rearranged="$rearranged $opt" + fi + done + + echo "$rearranged" +} + # ########################################################################### # End mysql_options package # ########################################################################### From 6e964261b760116c93996d0a78e11dd62f3be814 Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Wed, 6 Mar 2013 14:13:05 -0300 Subject: [PATCH 4/6] update-samples on pt-ms --- bin/pt-mysql-summary | 23 +++++++++++++++++++---- t/pt-stalk/pt-stalk.t | 4 ++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/bin/pt-mysql-summary b/bin/pt-mysql-summary index 4233722d..98466e53 100755 --- a/bin/pt-mysql-summary +++ b/bin/pt-mysql-summary @@ -477,15 +477,30 @@ mysql_options() { MYSQL_ARGS="$MYSQL_ARGS --host=$OPT_HOST" fi if [ -n "$OPT_USER" ]; then - MYSQL_ARGS="$MYSQL_ARGS --user='$OPT_USER'" + MYSQL_ARGS="$MYSQL_ARGS --user=$OPT_USER" fi if [ -n "$OPT_PASSWORD" ]; then - MYSQL_ARGS="$MYSQL_ARGS --password='$OPT_PASSWORD'" + MYSQL_ARGS="$MYSQL_ARGS --password=$OPT_PASSWORD" fi echo $MYSQL_ARGS } +arrange_mysql_options() { + local opts="$1" + + local rearranged="" + for opt in $opts; do + if [ "$(echo $opt | awk -F= '{print $1}')" = "--defaults-file" ]; then + rearranged="$opt $rearranged" + else + rearranged="$rearranged $opt" + fi + done + + echo "$rearranged" +} + # ########################################################################### # End mysql_options package # ########################################################################### @@ -2229,7 +2244,7 @@ report_mysql_summary () { || [ -e "$dir/mysqldump" -a -s "$dir/mysqldump" ]; then reply="y" elif [ -t 0 -a -t 1 ]; then - printf "Would you like to mysqldump -d the schema and analyze it? y/n " + echo -n "Would you like to mysqldump -d the schema and analyze it? y/n " read reply reply=${reply:-n} fi @@ -2237,7 +2252,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?" - printf "Type the name of the database, or press Enter to dump all of them. " + echo -n "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" )" diff --git a/t/pt-stalk/pt-stalk.t b/t/pt-stalk/pt-stalk.t index 464a4d45..775af576 100644 --- a/t/pt-stalk/pt-stalk.t +++ b/t/pt-stalk/pt-stalk.t @@ -144,7 +144,7 @@ like( cleanup(); -$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --verbose 3 -- --defaults-file=$cnf"); +$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --variable Threads_running --dest $dest --verbose 3 -- --defaults-file=$cnf"); PerconaTest::wait_for_files($pid_file, $log_file); PerconaTest::wait_for_sh("grep -q 'Check results' $log_file >/dev/null"); @@ -155,7 +155,7 @@ like( $output, qr/Check results: Threads_running=\d+, matched=no, cycles_true=0/, "Matching results logged with --verbose 3" -) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`); +) or diag(`cat $dest/*-output 2>/dev/null`); # ############################################################################# # --verbose 1 (just errors and warnings) From fb405b17f6ebbd5198d04a5f04678eaeddac4da8 Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Wed, 6 Mar 2013 17:05:11 -0300 Subject: [PATCH 5/6] Removed test for hosts's default --- t/lib/bash/mysql_options.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/t/lib/bash/mysql_options.sh b/t/lib/bash/mysql_options.sh index 2d966ce7..bc20421a 100644 --- a/t/lib/bash/mysql_options.sh +++ b/t/lib/bash/mysql_options.sh @@ -15,13 +15,6 @@ 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 # ############################################################################ @@ -29,6 +22,9 @@ is "$OPT_HOST" "localhost" "--host has default: localhost" parse_options "$PERCONA_TOOLKIT_BRANCH/bin/pt-mysql-summary" -F $cnf is "$OPT_DEFAULTS_FILE" "$cnf" "-F works" +parse_options "$PERCONA_TOOLKIT_BRANCH/bin/pt-mysql-summary" -u msandbox +is "$OPT_USER" "msandbox" "-u works" + # ############################################################################ # Done # ############################################################################ From a8aac7f6b3d8166c92df1144c5d17247b8e9cbb3 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Sat, 9 Mar 2013 11:47:10 -0700 Subject: [PATCH 6/6] Alphabetize pt-mysql-summary and pt-stalk options. --- bin/pt-mysql-summary | 74 ++++++++++++++++++++-------------------- bin/pt-stalk | 80 ++++++++++++++++++++++---------------------- 2 files changed, 77 insertions(+), 77 deletions(-) diff --git a/bin/pt-mysql-summary b/bin/pt-mysql-summary index 98466e53..834512cc 100755 --- a/bin/pt-mysql-summary +++ b/bin/pt-mysql-summary @@ -2525,7 +2525,7 @@ pt-mysql-summary - Summarize MySQL information nicely. =head1 SYNOPSIS -Usage: pt-mysql-summary [OPTIONS] [-- MYSQL OPTIONS] +Usage: pt-mysql-summary [OPTIONS] pt-mysql-summary conveniently summarizes the status and configuration of a MySQL database server so that you can learn about it at a glance. It is not @@ -2620,24 +2620,24 @@ unlike the system date and time printed earlier, so you can see whether the database and operating system times match. # Processlist ################################################ - + Command COUNT(*) Working SUM(Time) MAX(Time) ------------------------------ -------- ------- --------- --------- Binlog Dump 1 1 150000 150000 Query 1 1 0 0 - + User COUNT(*) Working SUM(Time) MAX(Time) ------------------------------ -------- ------- --------- --------- msandbox 2 2 150000 150000 - + Host COUNT(*) Working SUM(Time) MAX(Time) ------------------------------ -------- ------- --------- --------- localhost 2 2 150000 150000 - + db COUNT(*) Working SUM(Time) MAX(Time) ------------------------------ -------- ------- --------- --------- NULL 2 2 150000 150000 - + State COUNT(*) Working SUM(Time) MAX(Time) ------------------------------ -------- ------- --------- --------- Master has sent all binlog to 1 1 150000 150000 @@ -2730,22 +2730,22 @@ are fuzzy-rounded. Would you like to mysqldump -d the schema and analyze it? y/n y There are 4 databases. Would you like to dump all, or just one? Type the name of the database, or press Enter to dump all of them. - + Database Tables Views SPs Trigs Funcs FKs Partn mysql 24 performance_schema 17 sakila 16 7 3 6 3 22 - + Database MyISAM CSV PERFORMANCE_SCHEMA InnoDB mysql 22 2 performance_schema 17 sakila 8 15 - + Database BTREE FULLTEXT mysql 31 performance_schema sakila 63 1 - + c t s e l d i t m v s h i e n o a n i e a m a m t u n t t n d r a @@ -2952,22 +2952,6 @@ type: string Read this comma-separated list of config files. If specified, this must be the first option on the command line. -=item --help - -Print help and exit. - -=item --save-samples - -type: string - -Save the data files used to generate the summary in this directory. - -=item --read-samples - -type: string - -Create a report from the files found in this directory. - =item --databases type: string @@ -2976,16 +2960,6 @@ Names of databases to summarize. If you want all of them, you can use the value C<--all-databases>; you can also pass in a comma-separated list of database names. If not provided, the program will ask you for manual input. -=item --sleep - -type: int; default: 10 - -Seconds to sleep when gathering status counters. - -=item --version - -Print tool's version and exit. - =item --defaults-file short form: -F; type: string @@ -2993,6 +2967,10 @@ short form: -F; type: string Only read mysql options from the given file. You must give an absolute pathname. +=item --help + +Print help and exit. + =item --host short form: -h; type: string @@ -3011,6 +2989,24 @@ short form: -P; type: int Port number to use for connection. +=item --read-samples + +type: string + +Create a report from the files found in this directory. + +=item --save-samples + +type: string + +Save the data files used to generate the summary in this directory. + +=item --sleep + +type: int; default: 10 + +Seconds to sleep when gathering status counters. + =item --socket short form: -S; type: string @@ -3023,10 +3019,14 @@ short form: -u; type: string User for login if not current user. +=item --version + +Print tool's version and exit. + =back =head1 ENVIRONMENT - + This tool does not use any environment variables. =head1 SYSTEM REQUIREMENTS diff --git a/bin/pt-stalk b/bin/pt-stalk index 6d916814..43dc4fcf 100755 --- a/bin/pt-stalk +++ b/bin/pt-stalk @@ -1474,12 +1474,12 @@ pt-stalk - Gather forensic data about MySQL when a problem occurs. =head1 SYNOPSIS -Usage: pt-stalk [OPTIONS] [-- EXTRA MYSQL OPTIONS] +Usage: pt-stalk [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 +to help in diagnosing problems. It is designed to run as a daemon with root privileges, so that you can diagnose intermittent problems that you cannot -observe directly. You can also use it to execute a custom command, or to gather +observe directly. You can also use it to execute a custom command, or to gather the data on demand without waiting for the trigger to happen. =head1 RISKS @@ -1648,6 +1648,13 @@ to fire when the problem recovers quickly. Daemonize the tool. This causes the tool to fork into the background and log its output as specified in --log. +=item --defaults-file + +short form: -F; type: string + +Only read mysql options from the given file. You must give an absolute +pathname. + =item --dest type: string; default: /var/lib/pt-stalk @@ -1744,6 +1751,12 @@ plugin-specific global variables with "PLUGIN_" or make them local. Print help and exit. +=item --host + +short form: -h; type: string + +Host to connect to. + =item --interval type: int; default: 1 @@ -1777,6 +1790,12 @@ type: string Send mail to this list of addresses when data is collected. +=item --password + +short form: -p; type: string + +Password to use when connecting. + =item --pid type: string; default: /var/run/pt-stalk.pid @@ -1847,6 +1866,12 @@ Plugins can stop the tool by setting the global variable C to C<1>. In this case, the global variable C should also be set to indicate why the tool was stopped. +=item --port + +short form: -P; type: int + +Port number to use for connection. + =item --prefix type: string @@ -1892,6 +1917,12 @@ continuously, which might be a problem if the collection process is intrusive. It also prevents filling up the disk or gathering too much data to analyze reasonably. +=item --socket + +short form: -S; type: string + +Socket file to use for connection. + =item --stalk default: yes; negatable: yes @@ -1915,6 +1946,12 @@ type: int; default: 25 The threshold at which the diagnostic trigger should fire. See L<"--function"> for details. +=item --user + +short form: -u; type: string + +User for login if not current user. + =item --variable type: string; default: Threads_running @@ -1941,43 +1978,6 @@ 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 - -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