pt-mysql-summary: Use mktemp through the tmpdir package.

This commit is contained in:
Brian Fraser
2012-01-03 14:52:57 -03:00
parent 650641b052
commit 0ca763c81b
2 changed files with 122 additions and 78 deletions

View File

@@ -13,6 +13,47 @@ usage() {
exit 1 exit 1
} }
# ###########################################################################
# tmpdir 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/tmpdir.sh
# t/lib/bash/tmpdir.sh
# See https://launchpad.net/percona-toolkit for more information.
# ###########################################################################
# pt-mysql-summary isn't ready for this yet.
# set -u
TMPDIR=""
mk_tmpdir() {
local dir=${1:-""}
if [ -n "$dir" ]; then
if [ ! -d "$dir" ]; then
mkdir $dir || die "Cannot make tmpdir $dir"
fi
TMPDIR="$dir"
else
local tool=`basename $0`
local pid="$$"
TMPDIR=`mktemp -d /tmp/${tool}.${pid}.XXXXX` \
|| die "Cannot make secure tmpdir"
fi
}
rm_tmpdir() {
if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then
rm -rf $TMPDIR
fi
TMPDIR=""
}
# ###########################################################################
# End tmpdir package
# ###########################################################################
# ######################################################################## # ########################################################################
# Some global setup is necessary for cross-platform compatibility, even # Some global setup is necessary for cross-platform compatibility, even
# when sourcing this script for testing purposes. # when sourcing this script for testing purposes.
@@ -62,9 +103,9 @@ fuzzy_formula='
# symlink them to /etc/passwd and then run this program as root. Call this # symlink them to /etc/passwd and then run this program as root. Call this
# function with "rm" or "touch" as an argument. # function with "rm" or "touch" as an argument.
temp_files() { temp_files() {
for file in /tmp/percona-toolkit{,-mysql-variables,-mysql-status,-innodb-status} \ for file in $TMPDIR/percona-toolkit{,-mysql-variables,-mysql-status,-innodb-status} \
/tmp/percona-toolkit{2,-mysql-databases,-mysql-processlist,-noncounters} \ $TMPDIR/percona-toolkit{2,-mysql-databases,-mysql-processlist,-noncounters} \
/tmp/percona-toolkit-mysql{dump,-slave}; $TMPDIR/percona-toolkit-mysql{dump,-slave};
do do
case "$1" in case "$1" in
touch) touch)
@@ -127,16 +168,16 @@ secs_to_time () {
}' }'
} }
# gets a value from /tmp/percona-toolkit-mysql-variables. Returns zero if it doesn't # gets a value from $TMPDIR/percona-toolkit-mysql-variables. Returns zero if it doesn't
# exist. # exist.
get_var () { get_var () {
v="$($AP_AWK "\$1 ~ /^$1$/ { print \$2 }" /tmp/percona-toolkit-mysql-variables)" v="$($AP_AWK "\$1 ~ /^$1$/ { print \$2 }" $TMPDIR/percona-toolkit-mysql-variables)"
echo "${v:-0}" echo "${v:-0}"
} }
# Returns true if a variable exists # Returns true if a variable exists
var_exists () { var_exists () {
$AP_GREP "$1" /tmp/percona-toolkit-mysql-variables >/dev/null 2>&1; $AP_GREP "$1" $TMPDIR/percona-toolkit-mysql-variables >/dev/null 2>&1;
} }
# Returns "Enabled", "Disabled", or "Not Supported" depending on whether the # Returns "Enabled", "Disabled", or "Not Supported" depending on whether the
@@ -145,7 +186,7 @@ var_exists () {
# (string equal) to some value. # (string equal) to some value.
feat_on() { feat_on() {
if var_exists $1 ; then if var_exists $1 ; then
var="$($AP_AWK "\$1 ~ /^$1$/ { print \$2 }" /tmp/percona-toolkit-mysql-variables)" var="$($AP_AWK "\$1 ~ /^$1$/ { print \$2 }" $TMPDIR/percona-toolkit-mysql-variables)"
if [ "${var}" = "ON" ]; then if [ "${var}" = "ON" ]; then
echo "Enabled" echo "Enabled"
elif [ "${var}" = "OFF" -o "${var}" = "0" -o -z "${var}" ]; then elif [ "${var}" = "OFF" -o "${var}" = "0" -o -z "${var}" ]; then
@@ -172,10 +213,10 @@ feat_on() {
fi fi
} }
# gets a value from /tmp/percona-toolkit-mysql-status. Returns zero if it doesn't # gets a value from $TMPDIR/percona-toolkit-mysql-status. Returns zero if it doesn't
# exist. # exist.
get_stat () { get_stat () {
v="$($AP_AWK "\$1 ~ /^$1$/ { print \$2 }" /tmp/percona-toolkit-mysql-status)" v="$($AP_AWK "\$1 ~ /^$1$/ { print \$2 }" $TMPDIR/percona-toolkit-mysql-status)"
echo "${v:-0}" echo "${v:-0}"
} }
@@ -195,12 +236,12 @@ fuzzy_pct () {
# Functions for parsing specific files and getting desired info from them. # Functions for parsing specific files and getting desired info from them.
# These are called from within main() and are separated so they can be tested # These are called from within main() and are separated so they can be tested
# easily. The calling convention is that the data they need to run is prepared # easily. The calling convention is that the data they need to run is prepared
# first by putting it into /tmp/percona-toolkit. Then code that's testing just needs to # first by putting it into $TMPDIR/percona-toolkit. Then code that's testing
# put sample data into /tmp/percona-toolkit and call it. # just needs to put sample data into $TMPDIR/percona-toolkit and call it.
# ############################################################################## # ##############################################################################
# Parses the output of 'ps -e -o args | $AP_GREP mysqld' or 'ps auxww...' # Parses the output of 'ps -e -o args | $AP_GREP mysqld' or 'ps auxww...'
# which should be in /tmp/percona-toolkit. # which should be in $TMPDIR/percona-toolkit.
parse_mysqld_instances () { parse_mysqld_instances () {
local file=$1 local file=$1
echo " Port Data Directory Socket" echo " Port Data Directory Socket"
@@ -224,7 +265,7 @@ parse_mysqld_instances () {
} }
# Tries to find the my.cnf file by examining 'ps' output, which should be in # Tries to find the my.cnf file by examining 'ps' output, which should be in
# /tmp/percona-toolkit. You have to specify the port for the instance you are # $TMPDIR/percona-toolkit. You have to specify the port for the instance you are
# interested in, in case there are multiple instances. # interested in, in case there are multiple instances.
find_my_cnf_file() { find_my_cnf_file() {
local file=$1 local file=$1
@@ -240,7 +281,7 @@ find_my_cnf_file() {
fi fi
} }
# Gets the MySQL system time. Uses input from /tmp/percona-toolkit-mysql-variables. # Gets the MySQL system time. Uses input from $TMPDIR/percona-toolkit-mysql-variables.
get_mysql_timezone () { get_mysql_timezone () {
tz="$(get_var time_zone)" tz="$(get_var time_zone)"
if [ "${tz}" = "SYSTEM" ]; then if [ "${tz}" = "SYSTEM" ]; then
@@ -249,14 +290,14 @@ get_mysql_timezone () {
echo "${tz}" echo "${tz}"
} }
# Gets the MySQL system version. Uses input from /tmp/percona-toolkit-mysql-variables. # Gets the MySQL system version. Uses input from $TMPDIR/percona-toolkit-mysql-variables.
get_mysql_version () { get_mysql_version () {
name_val Version "$(get_var version) $(get_var version_comment)" name_val Version "$(get_var version) $(get_var version_comment)"
name_val "Built On" "$(get_var version_compile_os) $(get_var version_compile_machine)" name_val "Built On" "$(get_var version_compile_os) $(get_var version_compile_machine)"
} }
# Gets the system start and uptime in human readable format. Last restart date # Gets the system start and uptime in human readable format. Last restart date
# should be in /tmp/percona-toolkit. # should be in $TMPDIR/percona-toolkit.
get_mysql_uptime () { get_mysql_uptime () {
local file=$1 local file=$1
restart="$(cat $file)" restart="$(cat $file)"
@@ -265,7 +306,7 @@ get_mysql_uptime () {
echo "${restart} (up ${uptime})" echo "${restart} (up ${uptime})"
} }
# Summarizes the output of SHOW MASTER LOGS, which is in /tmp/percona-toolkit # Summarizes the output of SHOW MASTER LOGS, which is in $TMPDIR/percona-toolkit
summarize_binlogs () { summarize_binlogs () {
local file=$1 local file=$1
name_val "Binlogs" $(wc -l $file) name_val "Binlogs" $(wc -l $file)
@@ -282,7 +323,7 @@ format_binlog_filters () {
} }
# Takes as input a file that has two samples of SHOW STATUS, columnized next to # Takes as input a file that has two samples of SHOW STATUS, columnized next to
# each other. These should be in /tmp/percona-toolkit. Outputs fuzzy-ed numbers: # each other. These should be in $TMPDIR/percona-toolkit. Outputs fuzzy-ed numbers:
# absolute, all-time per second, and per-second over the interval between the # absolute, all-time per second, and per-second over the interval between the
# samples. Omits any rows that are all zeroes. # samples. Omits any rows that are all zeroes.
format_status_variables () { format_status_variables () {
@@ -387,7 +428,7 @@ summarize_processlist () {
echo echo
} }
# Pretty-prints the my.cnf file, which should be in /tmp/percona-toolkit. It's super # Pretty-prints the my.cnf file, which should be in $TMPDIR/percona-toolkit. It's super
# annoying, but some *modern* versions of awk don't support POSIX character # annoying, but some *modern* versions of awk don't support POSIX character
# sets in regular expressions, like [[:space:]] (looking at you, Debian). So # sets in regular expressions, like [[:space:]] (looking at you, Debian). So
# the below patterns contain [<space><tab>] and must remain that way. # the below patterns contain [<space><tab>] and must remain that way.
@@ -545,8 +586,8 @@ format_innodb_status () {
name_val "Pending I/O Writes" "$(find_pending_io_writes "${file}")" name_val "Pending I/O Writes" "$(find_pending_io_writes "${file}")"
name_val "Pending I/O Flushes" "$(find_pending_io_flushes "${file}")" name_val "Pending I/O Flushes" "$(find_pending_io_flushes "${file}")"
$AP_AWK -F, '/^---TRANSACTION/{print $2}' "${file}" \ $AP_AWK -F, '/^---TRANSACTION/{print $2}' "${file}" \
| $AP_SED -e 's/ [0-9]* sec.*//' | sort | uniq -c > /tmp/percona-toolkit2 | $AP_SED -e 's/ [0-9]* sec.*//' | sort | uniq -c > $TMPDIR/percona-toolkit2
name_val "Transaction States" "$(group_concat /tmp/percona-toolkit2)" name_val "Transaction States" "$(group_concat $TMPDIR/percona-toolkit2)"
if $AP_GREP 'TABLE LOCK table' "${file}" >/dev/null ; then if $AP_GREP 'TABLE LOCK table' "${file}" >/dev/null ; then
echo "Tables Locked" echo "Tables Locked"
$AP_AWK '/^TABLE LOCK table/{print $4}' "${file}" \ $AP_AWK '/^TABLE LOCK table/{print $4}' "${file}" \
@@ -633,9 +674,9 @@ format_overall_db_stats () {
printf fmt, db, counts[db ",tables"], counts[db ",views"], counts[db ",sps"], counts[db ",trg"], counts[db ",func"], counts[db ",fk"], counts[db ",partn"]; printf fmt, db, counts[db ",tables"], counts[db ",views"], counts[db ",sps"], counts[db ",trg"], counts[db ",func"], counts[db ",fk"], counts[db ",partn"];
} }
} }
' $file > /tmp/percona-toolkit ' $file > $TMPDIR/percona-toolkit
head -n2 /tmp/percona-toolkit head -n2 $TMPDIR/percona-toolkit
tail -n +3 /tmp/percona-toolkit | sort tail -n +3 $TMPDIR/percona-toolkit | sort
echo echo
# Now do the summary of engines per DB # Now do the summary of engines per DB
@@ -693,9 +734,9 @@ format_overall_db_stats () {
print ""; print "";
} }
} }
' $file > /tmp/percona-toolkit ' $file > $TMPDIR/percona-toolkit
head -n1 /tmp/percona-toolkit head -n1 $TMPDIR/percona-toolkit
tail -n +2 /tmp/percona-toolkit | sort tail -n +2 $TMPDIR/percona-toolkit | sort
echo echo
# Now do the summary of index types per DB. Careful -- index is a reserved # Now do the summary of index types per DB. Careful -- index is a reserved
@@ -766,9 +807,9 @@ format_overall_db_stats () {
print ""; print "";
} }
} }
' $file > /tmp/percona-toolkit ' $file > $TMPDIR/percona-toolkit
head -n1 /tmp/percona-toolkit head -n1 $TMPDIR/percona-toolkit
tail -n +2 /tmp/percona-toolkit | sort tail -n +2 $TMPDIR/percona-toolkit | sort
echo echo
# Now do the summary of datatypes per DB # Now do the summary of datatypes per DB
@@ -857,10 +898,10 @@ format_overall_db_stats () {
print ""; print "";
} }
} }
' $file > /tmp/percona-toolkit ' $file > $TMPDIR/percona-toolkit
hdr=$($AP_GREP -n Database /tmp/percona-toolkit | cut -d: -f1); hdr=$($AP_GREP -n Database $TMPDIR/percona-toolkit | cut -d: -f1);
head -n${hdr} /tmp/percona-toolkit head -n${hdr} $TMPDIR/percona-toolkit
tail -n +$((${hdr} + 1)) /tmp/percona-toolkit | sort tail -n +$((${hdr} + 1)) $TMPDIR/percona-toolkit | sort
echo echo
} }
@@ -878,6 +919,7 @@ main() {
export PATH="/usr/gnu/bin/:/usr/xpg4/bin/:${PATH}" export PATH="/usr/gnu/bin/:/usr/xpg4/bin/:${PATH}"
# Set up temporary files. # Set up temporary files.
mk_tmpdir
temp_files "rm" temp_files "rm"
temp_files "touch" temp_files "touch"
@@ -887,25 +929,26 @@ main() {
section Percona_Toolkit_MySQL_Summary_Report section Percona_Toolkit_MySQL_Summary_Report
name_val "System time" "`date -u +'%F %T UTC'` (local TZ: `date +'%Z %z'`)" name_val "System time" "`date -u +'%F %T UTC'` (local TZ: `date +'%Z %z'`)"
section Instances section Instances
ps auxww 2>/dev/null | $AP_GREP mysqld > /tmp/percona-toolkit ps auxww 2>/dev/null | $AP_GREP mysqld > $TMPDIR/percona-toolkit
parse_mysqld_instances /tmp/percona-toolkit parse_mysqld_instances $TMPDIR/percona-toolkit
# ######################################################################## # ########################################################################
# Fetch some basic info so we can start # Fetch some basic info so we can start
# ######################################################################## # ########################################################################
mysql "$@" -ss -e 'SELECT CURRENT_USER()' > /tmp/percona-toolkit mysql "$@" -ss -e 'SELECT CURRENT_USER()' > $TMPDIR/percona-toolkit
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
echo "Cannot connect to mysql, please specify command-line options." echo "Cannot connect to mysql, please specify command-line options."
temp_files "rm" temp_files "rm"
rm_tmpdir
exit 1 exit 1
fi fi
user="$(cat /tmp/percona-toolkit)"; user="$(cat $TMPDIR/percona-toolkit)";
mysql "$@" -ss -e 'SHOW /*!40100 GLOBAL*/ VARIABLES' > /tmp/percona-toolkit-mysql-variables mysql "$@" -ss -e 'SHOW /*!40100 GLOBAL*/ VARIABLES' > $TMPDIR/percona-toolkit-mysql-variables
mysql "$@" -ss -e 'SHOW /*!50000 GLOBAL*/ STATUS' > /tmp/percona-toolkit-mysql-status mysql "$@" -ss -e 'SHOW /*!50000 GLOBAL*/ STATUS' > $TMPDIR/percona-toolkit-mysql-status
mysql "$@" -ss -e 'SHOW DATABASES' > /tmp/percona-toolkit-mysql-databases 2>/dev/null mysql "$@" -ss -e 'SHOW DATABASES' > $TMPDIR/percona-toolkit-mysql-databases 2>/dev/null
mysql "$@" -ssE -e 'SHOW SLAVE STATUS' > /tmp/percona-toolkit-mysql-slave 2>/dev/null mysql "$@" -ssE -e 'SHOW SLAVE STATUS' > $TMPDIR/percona-toolkit-mysql-slave 2>/dev/null
mysql "$@" -ssE -e 'SHOW /*!50000 ENGINE*/ INNODB STATUS' > /tmp/percona-toolkit-innodb-status 2>/dev/null mysql "$@" -ssE -e 'SHOW /*!50000 ENGINE*/ INNODB STATUS' > $TMPDIR/percona-toolkit-innodb-status 2>/dev/null
mysql "$@" -ssE -e 'SHOW FULL PROCESSLIST' > /tmp/percona-toolkit-mysql-processlist 2>/dev/null mysql "$@" -ssE -e 'SHOW FULL PROCESSLIST' > $TMPDIR/percona-toolkit-mysql-processlist 2>/dev/null
now="$(mysql "$@" -ss -e 'SELECT NOW()')" now="$(mysql "$@" -ss -e 'SELECT NOW()')"
port="$(get_var port)" port="$(get_var port)"
@@ -920,16 +963,16 @@ main() {
uptime="$(get_stat Uptime)" uptime="$(get_stat Uptime)"
mysql "$@" -ss -e "SELECT LEFT(NOW() - INTERVAL ${uptime} SECOND, 16)" \ mysql "$@" -ss -e "SELECT LEFT(NOW() - INTERVAL ${uptime} SECOND, 16)" \
> /tmp/percona-toolkit > $TMPDIR/percona-toolkit
name_val Started "$(get_mysql_uptime /tmp/percona-toolkit)" name_val Started "$(get_mysql_uptime $TMPDIR/percona-toolkit)"
name_val Databases "$($AP_GREP -c . /tmp/percona-toolkit-mysql-databases)" name_val Databases "$($AP_GREP -c . $TMPDIR/percona-toolkit-mysql-databases)"
name_val Datadir "$(get_var datadir)" name_val Datadir "$(get_var datadir)"
procs="$(get_stat Threads_connected)" procs="$(get_stat Threads_connected)"
procr="$(get_stat Threads_running)" procr="$(get_stat Threads_running)"
name_val Processes "$(fuzz ${procs}) connected, $(fuzz ${procr}) running" name_val Processes "$(fuzz ${procs}) connected, $(fuzz ${procr}) running"
if [ -s /tmp/percona-toolkit-mysql-slave ]; then slave=""; else slave="not "; fi if [ -s $TMPDIR/percona-toolkit-mysql-slave ]; then slave=""; else slave="not "; fi
slavecount=$($AP_GREP -c 'Binlog Dump' /tmp/percona-toolkit-mysql-processlist) slavecount=$($AP_GREP -c 'Binlog Dump' $TMPDIR/percona-toolkit-mysql-processlist)
name_val Replication "Is ${slave}a slave, has ${slavecount} slaves connected" name_val Replication "Is ${slave}a slave, has ${slavecount} slaves connected"
# TODO move this into a section with other files: error log, slow log and # TODO move this into a section with other files: error log, slow log and
@@ -942,7 +985,7 @@ main() {
# Processlist, sliced several different ways # Processlist, sliced several different ways
# ######################################################################## # ########################################################################
section Processlist section Processlist
summarize_processlist /tmp/percona-toolkit-mysql-processlist summarize_processlist $TMPDIR/percona-toolkit-mysql-processlist
# ######################################################################## # ########################################################################
# Queries and query plans # Queries and query plans
@@ -951,7 +994,7 @@ main() {
sleep 10 sleep 10
# TODO: gather this data in the same format as normal: stats, TS line # TODO: gather this data in the same format as normal: stats, TS line
mysql "$@" -ss -e 'SHOW /*!50000 GLOBAL*/ STATUS' \ mysql "$@" -ss -e 'SHOW /*!50000 GLOBAL*/ STATUS' \
| join /tmp/percona-toolkit-mysql-status - > /tmp/percona-toolkit | join $TMPDIR/percona-toolkit-mysql-status - > $TMPDIR/percona-toolkit
# Make a file with a list of things we want to omit because they aren't # Make a file with a list of things we want to omit because they aren't
# counters, they are gauges (in RRDTool terminology). Gauges are shown # counters, they are gauges (in RRDTool terminology). Gauges are shown
# elsewhere in the output. # elsewhere in the output.
@@ -975,9 +1018,9 @@ main() {
Threads_cached Threads_connected Threads_running \ Threads_cached Threads_connected Threads_running \
Uptime_since_flush_status; Uptime_since_flush_status;
do do
echo "${var}" >> /tmp/percona-toolkit-noncounters echo "${var}" >> $TMPDIR/percona-toolkit-noncounters
done done
format_status_variables /tmp/percona-toolkit | $AP_GREP -v -f /tmp/percona-toolkit-noncounters format_status_variables $TMPDIR/percona-toolkit | $AP_GREP -v -f $TMPDIR/percona-toolkit-noncounters
# ######################################################################## # ########################################################################
# Table cache # Table cache
@@ -1054,22 +1097,22 @@ main() {
trg_arg="${trg_arg} ${triggers}"; trg_arg="${trg_arg} ${triggers}";
fi fi
# Find out which databases to dump # Find out which databases to dump
num_dbs="$($AP_GREP -c . /tmp/percona-toolkit-mysql-databases)" num_dbs="$($AP_GREP -c . $TMPDIR/percona-toolkit-mysql-databases)"
echo "There are ${num_dbs} databases. Would you like to dump all, or just one?" 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. " echo -n "Type the name of the database, or press Enter to dump all of them. "
read dbtodump read dbtodump
mysqldump "$@" --no-data --skip-comments \ mysqldump "$@" --no-data --skip-comments \
--skip-add-locks --skip-add-drop-table --compact \ --skip-add-locks --skip-add-drop-table --compact \
--skip-lock-all-tables --skip-lock-tables --skip-set-charset \ --skip-lock-all-tables --skip-lock-tables --skip-set-charset \
${trg_arg} ${dbtodump:---all-databases} > /tmp/percona-toolkit-mysqldump ${trg_arg} ${dbtodump:---all-databases} > $TMPDIR/percona-toolkit-mysqldump
# Test the result by checking the file, not by the exit status, because we # Test the result by checking the file, not by the exit status, because we
# might get partway through and then die, and the info is worth analyzing # might get partway through and then die, and the info is worth analyzing
# anyway. # anyway.
if $AP_GREP 'CREATE TABLE' /tmp/percona-toolkit-mysqldump >/dev/null 2>&1; then if $AP_GREP 'CREATE TABLE' $TMPDIR/percona-toolkit-mysqldump >/dev/null 2>&1; then
format_overall_db_stats /tmp/percona-toolkit-mysqldump format_overall_db_stats $TMPDIR/percona-toolkit-mysqldump
else else
echo "Skipping schema analysis due to apparent error in dump file" echo "Skipping schema analysis due to apparent error in dump file"
rm -f /tmp/percona-toolkit-mysqldump rm -f $TMPDIR/percona-toolkit-mysqldump
fi fi
else else
echo "Skipping schema analysis" echo "Skipping schema analysis"
@@ -1079,23 +1122,23 @@ main() {
# Noteworthy Technologies # Noteworthy Technologies
# ######################################################################## # ########################################################################
section Noteworthy_Technologies section Noteworthy_Technologies
if [ -e /tmp/percona-toolkit-mysqldump ]; then if [ -e $TMPDIR/percona-toolkit-mysqldump ]; then
if $AP_GREP FULLTEXT /tmp/percona-toolkit-mysqldump > /dev/null; then if $AP_GREP FULLTEXT $TMPDIR/percona-toolkit-mysqldump > /dev/null; then
name_val "Full Text Indexing" Yes name_val "Full Text Indexing" Yes
else else
name_val "Full Text Indexing" No name_val "Full Text Indexing" No
fi fi
if $AP_GREP 'GEOMETRY\|POINT\|LINESTRING\|POLYGON' /tmp/percona-toolkit-mysqldump > /dev/null; then if $AP_GREP 'GEOMETRY\|POINT\|LINESTRING\|POLYGON' $TMPDIR/percona-toolkit-mysqldump > /dev/null; then
name_val "Geospatial Types" Yes name_val "Geospatial Types" Yes
else else
name_val "Geospatial Types" No name_val "Geospatial Types" No
fi fi
if $AP_GREP 'FOREIGN KEY' /tmp/percona-toolkit-mysqldump > /dev/null; then if $AP_GREP 'FOREIGN KEY' $TMPDIR/percona-toolkit-mysqldump > /dev/null; then
name_val "Foreign Keys" Yes name_val "Foreign Keys" Yes
else else
name_val "Foreign Keys" No name_val "Foreign Keys" No
fi fi
if $AP_GREP 'PARTITION BY' /tmp/percona-toolkit-mysqldump > /dev/null; then if $AP_GREP 'PARTITION BY' $TMPDIR/percona-toolkit-mysqldump > /dev/null; then
name_val "Partitioning" Yes name_val "Partitioning" Yes
else else
name_val "Partitioning" No name_val "Partitioning" No
@@ -1175,8 +1218,8 @@ main() {
name_val "Adaptive Flushing" $(get_var innodb_adaptive_flushing) name_val "Adaptive Flushing" $(get_var innodb_adaptive_flushing)
name_val "Adaptive Checkpoint" $(get_var innodb_adaptive_checkpoint) name_val "Adaptive Checkpoint" $(get_var innodb_adaptive_checkpoint)
if [ -s /tmp/percona-toolkit-innodb-status ]; then if [ -s $TMPDIR/percona-toolkit-innodb-status ]; then
format_innodb_status /tmp/percona-toolkit-innodb-status format_innodb_status $TMPDIR/percona-toolkit-innodb-status
fi fi
fi fi
@@ -1211,15 +1254,15 @@ main() {
section Binary_Logging section Binary_Logging
binlog=$(get_var log_bin) binlog=$(get_var log_bin)
if [ "${binlog}" ]; then if [ "${binlog}" ]; then
mysql "$@" -ss -e 'SHOW MASTER LOGS' > /tmp/percona-toolkit 2>/dev/null mysql "$@" -ss -e 'SHOW MASTER LOGS' > $TMPDIR/percona-toolkit 2>/dev/null
summarize_binlogs /tmp/percona-toolkit summarize_binlogs $TMPDIR/percona-toolkit
format="$(get_var binlog_format)" format="$(get_var binlog_format)"
name_val binlog_format "${format:-STATEMENT}" name_val binlog_format "${format:-STATEMENT}"
name_val expire_logs_days $(get_var expire_logs_days) name_val expire_logs_days $(get_var expire_logs_days)
name_val sync_binlog $(get_var sync_binlog) name_val sync_binlog $(get_var sync_binlog)
name_val server_id $(get_var server_id) name_val server_id $(get_var server_id)
mysql "$@" -ss -e 'SHOW MASTER STATUS' > /tmp/percona-toolkit 2>/dev/null mysql "$@" -ss -e 'SHOW MASTER STATUS' > $TMPDIR/percona-toolkit 2>/dev/null
format_binlog_filters /tmp/percona-toolkit format_binlog_filters $TMPDIR/percona-toolkit
fi fi
# Replication: seconds behind, running, filters, skip_slave_start, skip_errors, # Replication: seconds behind, running, filters, skip_slave_start, skip_errors,
@@ -1252,8 +1295,8 @@ main() {
# If there is a my.cnf in a standard location, see if we can pretty-print it. # If there is a my.cnf in a standard location, see if we can pretty-print it.
# ######################################################################## # ########################################################################
section Configuration_File section Configuration_File
ps auxww 2>/dev/null | $AP_GREP mysqld > /tmp/percona-toolkit ps auxww 2>/dev/null | $AP_GREP mysqld > $TMPDIR/percona-toolkit
cnf_file=$(find_my_cnf_file /tmp/percona-toolkit ${port}); cnf_file=$(find_my_cnf_file $TMPDIR/percona-toolkit ${port});
if [ ! -e "${cnf_file}" ]; then if [ ! -e "${cnf_file}" ]; then
name_val "Config File" "Cannot autodetect, trying common locations" name_val "Config File" "Cannot autodetect, trying common locations"
cnf_file="/etc/my.cnf"; cnf_file="/etc/my.cnf";
@@ -1266,13 +1309,14 @@ main() {
fi fi
if [ -e "${cnf_file}" ]; then if [ -e "${cnf_file}" ]; then
name_val "Config File" "${cnf_file}" name_val "Config File" "${cnf_file}"
cat "${cnf_file}" > /tmp/percona-toolkit cat "${cnf_file}" > $TMPDIR/percona-toolkit
pretty_print_cnf_file /tmp/percona-toolkit pretty_print_cnf_file $TMPDIR/percona-toolkit
else else
name_val "Config File" "Cannot autodetect or find, giving up" name_val "Config File" "Cannot autodetect or find, giving up"
fi fi
temp_files "rm" temp_files "rm"
rm_tmpdir
# Make sure that we signal the end of the tool's output. # Make sure that we signal the end of the tool's output.
section The_End section The_End
@@ -1325,8 +1369,8 @@ See also L<"BUGS"> for more information on filing bugs and getting help.
pt-mysql-summary works by connecting to a MySQL database server and querying pt-mysql-summary works by connecting to a MySQL database server and querying
it for status and configuration information. It saves these bits of data it for status and configuration information. It saves these bits of data
into files in /tmp, and then formats them neatly with awk and other scripting into files in a temporary directory, and then formats them neatly with awk
languages. and other scripting languages.
To use, simply execute it. Optionally add the same command-line options To use, simply execute it. Optionally add the same command-line options
you would use to connect to MySQL, like C<pt-mysql-summary --user=foo>. you would use to connect to MySQL, like C<pt-mysql-summary --user=foo>.

View File

@@ -3,14 +3,14 @@
TESTS=3 TESTS=3
TEST_NAME="get_mysql_timezone" TEST_NAME="get_mysql_timezone"
cp samples/mysql-variables-001.txt /tmp/percona-toolkit-mysql-variables cp samples/mysql-variables-001.txt $TMPDIR/percona-toolkit-mysql-variables
is $(get_mysql_timezone) "EDT" is $(get_mysql_timezone) "EDT"
TEST_NAME="get_mysql_uptime" TEST_NAME="get_mysql_uptime"
cat <<EOF > $TMPDIR/expected cat <<EOF > $TMPDIR/expected
2010-05-27 11:38 (up 0+02:08:52) 2010-05-27 11:38 (up 0+02:08:52)
EOF EOF
cp samples/mysql-status-001.txt /tmp/percona-toolkit-mysql-status cp samples/mysql-status-001.txt $TMPDIR/percona-toolkit-mysql-status
echo "2010-05-27 11:38" > $TMPDIR/in echo "2010-05-27 11:38" > $TMPDIR/in
get_mysql_uptime $TMPDIR/in > $TMPDIR/got get_mysql_uptime $TMPDIR/in > $TMPDIR/got
no_diff $TMPDIR/got $TMPDIR/expected no_diff $TMPDIR/got $TMPDIR/expected
@@ -20,6 +20,6 @@ cat <<EOF > $TMPDIR/expected
Version | 5.0.51a-24+lenny2 (Debian) Version | 5.0.51a-24+lenny2 (Debian)
Built On | debian-linux-gnu i486 Built On | debian-linux-gnu i486
EOF EOF
cp samples/mysql-variables-001.txt /tmp/percona-toolkit-mysql-variables cp samples/mysql-variables-001.txt $TMPDIR/percona-toolkit-mysql-variables
get_mysql_version > $TMPDIR/got get_mysql_version > $TMPDIR/got
no_diff $TMPDIR/got $TMPDIR/expected no_diff $TMPDIR/got $TMPDIR/expected