Compare commits

..

11 Commits

Author SHA1 Message Date
svetasmirnova
3767e57e15 PT-2037 - added test for the situation when both --system-only and --mysql-only are specified 2022-01-27 19:21:04 +03:00
svetasmirnova
9427c16314 PT-2037 - regression fixes
Re-added fix for PT-1340 that was reverted by fix for PT-1398
2022-01-23 03:55:35 +03:00
svetasmirnova
623fdaec91 PT-2037 - option --system-only for pt-stalk
This commit:
1. Moves all changes to the proper place: lib/bash/collect.sh
2. Refactors pt-stalk so it is more modular
3. Places fix for PT-1734 into the right place: lib/bash/collect.sh
4. Fixes tests for PT-1336
2022-01-22 21:21:05 +03:00
svetasmirnova
1f6c95f524 PT-2037 - reviewer suggestions
Refactoring pt-stalk to make it easier to call system and MySQL data collections separately
2022-01-21 04:12:43 +03:00
svetasmirnova
d6e899404e PT-2037 Option --system-only for pt-stalk
Option --system-only triggers only operating system related captures, ignoring all others.
2022-01-19 18:41:05 +03:00
svetasmirnova
5a46d3df77 PT-2037 Added option --system-only to pt-stalk 2022-01-11 01:20:10 +03:00
Nurlan Moldomurov
1c725e94e6 PMM-9337 Update go 1.17 (#529) 2022-01-03 15:02:23 +03:00
Maxim Kondratenko
037b6ed502 SAAS-800 Integrate WhiteSource 2021-12-27 11:41:37 +02:00
Sveta Smirnova
b2860eee31 PT-1336 pt-stalk removes user files from destination (#524)
* PT-1336 Added file name checks and -maxdepth 1 parameter

* PT-1336 pt-stalk removes user files from the destination directory

* Added check that files to be removed were created by pt-stalk

* Added option -maxdepth 1 to find command, so the tool does not search for files in the nested directories

* Added unit tests

* This should fix PT-1812 also
2021-12-10 09:18:18 -03:00
Lenz Grimmer
fde683fb5d PT-1887: Fixed pt-diskstats to work on 5.x kernels (#526)
The amount of fields returned for disk statistics
changed in newer Linux kernel versions to 20 and
caused `pt-diskstat` to simply not provide any output
on these systems. Updated the check in the diskstats
parsing code to proceed with 20 fields as well.

Signed-off-by: Lenz Grimmer <lenz.grimmer@percona.com>
2021-12-03 13:19:36 -03:00
Carlos Salguero
a019907e6e PT-2023 Set out mode to utf8 (#523) 2021-11-18 14:41:35 -03:00
8 changed files with 494 additions and 302 deletions

View File

@@ -1,8 +1,7 @@
language: go
go:
- 1.15.x
- 1.14.x
- 1.17.x
- tip
services:

24
.whitesource Normal file
View File

@@ -0,0 +1,24 @@
{
"scanSettings": {
"configMode": "AUTO",
"configExternalURL": "",
"projectToken": "",
"baseBranches": [],
"enableLicenseViolations": true
},
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure",
"displayMode": "diff"
},
"issueSettings": {
"minSeverityLevel": "NONE"
},
"remediateSettings": {
"enableRenovate": false,
"dependencyDashboard": true,
"extends": [
"github>whitesource/merge-confidence:beta",
"github>samq-ghdemo/renovate:demo"
]
}
}

View File

@@ -2243,8 +2243,10 @@ sub parse_diskstats_line {
# linux kernel source => Documentation/iostats.txt
# 2.6+ => 14 fields
# 4.18+ => 18 fields
# 5.x+ => 20 fields (PT-1887)
my @num_fields = (14, 18, 20);
my @dev_stats = split ' ', $line;
return unless @dev_stats == 14 or @dev_stats == 18;
return unless grep {$_ == scalar(@dev_stats)} @num_fields;
my $read_bytes = $dev_stats[READ_SECTORS] * $block_size;
my $written_bytes = $dev_stats[WRITTEN_SECTORS] * $block_size;

View File

@@ -9,10 +9,10 @@ set -u
# ###########################################################################
# log_warn_die 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,
# with comments and its test file can be found in the GitHub repository at,
# lib/bash/log_warn_die.sh
# t/lib/bash/log_warn_die.sh
# See https://launchpad.net/percona-toolkit for more information.
# See https://github.com/percona/percona-toolkit for more information.
# ###########################################################################
@@ -57,10 +57,10 @@ _d () {
# ###########################################################################
# subshell 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,
# with comments and its test file can be found in the GitHub repository at,
# lib/bash/subshell.sh
# t/lib/bash/subshell.sh
# See https://launchpad.net/percona-toolkit for more information.
# See https://github.com/percona/percona-toolkit for more information.
# ###########################################################################
@@ -109,10 +109,10 @@ kill_all_subshells() {
# ###########################################################################
# parse_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,
# with comments and its test file can be found in the GitHub repository at,
# lib/bash/parse_options.sh
# t/lib/bash/parse_options.sh
# See https://launchpad.net/percona-toolkit for more information.
# See https://github.com/percona/percona-toolkit for more information.
# ###########################################################################
@@ -128,7 +128,6 @@ OPT_ERRS=0 # How many command line option errors
OPT_VERSION="" # If --version was specified
OPT_HELP="" # If --help was specified
OPT_ASK_PASS="" # If --ask-pass was specified
OPT_MYSQL_ONLY="" # If --mysql-only was specified
PO_DIR="" # Directory with program option spec files
usage() {
@@ -335,7 +334,7 @@ _eval_po() {
*)
echo "Invalid attribute in $opt_spec: $line" >&2
exit 1
esac
esac
done < "$opt_spec"
if [ -z "$opt" ]; then
@@ -459,7 +458,6 @@ _parse_command_line() {
else
spec=$(grep "^short form:-$opt\$" "$PT_TMPDIR"/po/* | cut -d ':' -f 1)
if [ -z "$spec" ]; then
option_error "Unknown option: $real_opt"
continue
fi
fi
@@ -475,7 +473,7 @@ _parse_command_line() {
if [ "$val" ]; then
option_error "Option $real_opt does not take a value"
continue
fi
fi
if [ "$opt_is_negated" ]; then
val=""
else
@@ -518,10 +516,10 @@ size_to_bytes() {
# ###########################################################################
# 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,
# with comments and its test file can be found in the GitHub repository at,
# lib/bash/mysql_options.sh
# t/lib/bash/mysql_options.sh
# See https://launchpad.net/percona-toolkit for more information.
# See https://github.com/percona/percona-toolkit for more information.
# ###########################################################################
@@ -544,16 +542,23 @@ mysql_options() {
if [ -n "$OPT_USER" ]; then
MYSQL_ARGS="$MYSQL_ARGS --user=$OPT_USER"
fi
if [ -n "$OPT_PASSWORD" ]; then
if [ -n "$OPT_ASK_PASS" ]; then
stty -echo
>&2 printf "Enter MySQL password: "
read GIVEN_PASS
stty echo
printf "\n"
MYSQL_ARGS="$MYSQL_ARGS --password=$GIVEN_PASS"
elif [ -n "$OPT_PASSWORD" ]; then
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
@@ -562,7 +567,7 @@ arrange_mysql_options() {
rearranged="$rearranged $opt"
fi
done
echo "$rearranged"
}
@@ -573,10 +578,10 @@ arrange_mysql_options() {
# ###########################################################################
# 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,
# with comments and its test file can be found in the GitHub repository at,
# lib/bash/tmpdir.sh
# t/lib/bash/tmpdir.sh
# See https://launchpad.net/percona-toolkit for more information.
# See https://github.com/percona/percona-toolkit for more information.
# ###########################################################################
@@ -614,10 +619,10 @@ rm_tmpdir() {
# ###########################################################################
# alt_cmds 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,
# with comments and its test file can be found in the GitHub repository at,
# lib/bash/alt_cmds.sh
# t/lib/bash/alt_cmds.sh
# See https://launchpad.net/percona-toolkit for more information.
# See https://github.com/percona/percona-toolkit for more information.
# ###########################################################################
@@ -661,10 +666,10 @@ _which() {
# ###########################################################################
# safeguards 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,
# with comments and its test file can be found in the GitHub repository at,
# lib/bash/safeguards.sh
# t/lib/bash/safeguards.sh
# See https://launchpad.net/percona-toolkit for more information.
# See https://github.com/percona/percona-toolkit for more information.
# ###########################################################################
@@ -717,10 +722,10 @@ check_disk_space() {
# ###########################################################################
# daemon 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,
# with comments and its test file can be found in the GitHub repository at,
# lib/bash/daemon.sh
# t/lib/bash/daemon.sh
# See https://launchpad.net/percona-toolkit for more information.
# See https://github.com/percona/percona-toolkit for more information.
# ###########################################################################
@@ -766,10 +771,10 @@ remove_pid_file() {
# ###########################################################################
# collect 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,
# with comments and its test file can be found in the GitHub repository at,
# lib/bash/collect.sh
# t/lib/bash/collect.sh
# See https://launchpad.net/percona-toolkit for more information.
# See https://github.com/percona/percona-toolkit for more information.
# ###########################################################################
@@ -796,9 +801,65 @@ collect() {
local d="$1" # directory to save results in
local p="$2" # prefix for each result file
local mysqld_pid=""
local cnt=$(($OPT_RUN_TIME / $OPT_SLEEP_COLLECT))
if [ ! "$OPT_SYSTEM_ONLY" ]; then
local mysqld_pid=""
local mysql_version=""
local mysql_error_log=""
local tail_error_log_pid=""
local have_lock_waits_table=""
local have_oprofile=""
local mysqladmin_pid=""
local mutex=""
local tcpdump_pid=""
local ps_instrumentation_enabled=""
collect_mysql_data_one
fi
if [ ! "$OPT_MYSQL_ONLY" ]; then
collect_system_data
fi
log "Loop start: $(date +'TS %s.%N %F %T')"
local start_time=$(date +'%s')
local curr_time=$start_time
local ts="$(date +"TS %s.%N %F %T")"
while [ $((curr_time - start_time)) -lt $OPT_RUN_TIME ]; do
if [ ! "$OPT_MYSQL_ONLY" ]; then
collect_system_data_loop
fi
if [ ! "$OPT_SYSTEM_ONLY" ]; then
collect_mysql_data_loop
fi
curr_time=$(date +'%s')
done
log "Loop end: $(date +'TS %s.%N %F %T')"
if [ ! "$OPT_SYSTEM_ONLY" ]; then
collect_mysql_data_two
fi
hostname > "$d/$p-hostname"
wait_for_subshells $OPT_RUN_TIME
kill_all_subshells
for file in "$d/$p-"*; do
if [ -z "$(grep -v '^TS ' --max-count 10 "$file")" ]; then
log "Removing empty file $file";
rm "$file"
fi
done
}
collect_mysql_data_one() {
if [ ! "$OPT_MYSQL_ONLY" ]; then
mysqld_pid=$(_pidof mysqld | awk '{print $1; exit;}')
port=$($CMD_MYSQL $EXT_ARGV -ss -e 'SELECT @@port')
mysqld_pid=$(lsof -i ":${port}" | grep -i listen | cut -f 3 -d" ")
fi
if [ "$CMD_PMAP" -a "$mysqld_pid" ]; then
@@ -820,27 +881,27 @@ collect() {
collect_mysql_variables "$d/$p-variables" &
sleep .5
local mysql_version="$(awk '/^version[^_]/{print substr($2,1,3)}' "$d/$p-variables")"
mysql_version="$(awk '/^version[^_]/{print substr($2,1,3)}' "$d/$p-variables")"
local mysql_error_log="$(awk '/^log_error/{print $2}' "$d/$p-variables")"
mysql_error_log="$(awk '/^log_error\s/{print $2}' "$d/$p-variables")"
if [ -z "$mysql_error_log" -a "$mysqld_pid" ]; then
log $mysqld_pid
mysql_error_log="$(ls -l /proc/$mysqld_pid/fd | awk '/ 2 ->/{print $NF}')"
fi
local tail_error_log_pid=""
if [ "$mysql_error_log" -a ! "$OPT_MYSQL_ONLY" ]; then
log "The MySQL error log seems to be $mysql_error_log"
tail -f "$mysql_error_log" >"$d/$p-log_error" &
tail_error_log_pid=$!
$CMD_MYSQLADMIN $EXT_ARGV debug
$CMD_MYSQLADMIN $EXT_ARGV
else
log "Could not find the MySQL error log"
fi
if [ "${mysql_version}" '>' "5.1" ]; then
local mutex="SHOW ENGINE INNODB MUTEX"
mutex="SHOW ENGINE INNODB MUTEX"
else
local mutex="SHOW MUTEX STATUS"
mutex="SHOW MUTEX STATUS"
fi
innodb_status 1
tokudb_status 1
@@ -849,7 +910,6 @@ collect() {
$CMD_MYSQL $EXT_ARGV -e "$mutex" >> "$d/$p-mutex-status1" &
open_tables >> "$d/$p-opentables1" &
local tcpdump_pid=""
if [ "$CMD_TCPDUMP" -a "$OPT_COLLECT_TCPDUMP" ]; then
local port=$(awk '/^port/{print $2}' "$d/$p-variables")
if [ "$port" ]; then
@@ -858,7 +918,6 @@ collect() {
fi
fi
local have_oprofile=""
if [ "$CMD_OPCONTROL" -a "$OPT_COLLECT_OPROFILE" ]; then
if $CMD_OPCONTROL --init; then
$CMD_OPCONTROL --start --no-vmlinux
@@ -869,114 +928,109 @@ collect() {
local strace_pid=$!
fi
if [ ! "$OPT_MYSQL_ONLY" ]; then
ps -eaF >> "$d/$p-ps" &
top -bn${OPT_RUN_TIME} >> "$d/$p-top" &
[ "$mysqld_pid" ] && _lsof $mysqld_pid >> "$d/$p-lsof" &
if [ "$CMD_SYSCTL" ]; then
$CMD_SYSCTL -a >> "$d/$p-sysctl" &
fi
if [ "$CMD_DMESG" ]; then
local UPTIME=`cat /proc/uptime | awk '{ print $1 }'`
local START_TIME=$(echo "$UPTIME 60" | awk '{print ($1 - $2)}')
$CMD_DMESG | perl -ne 'm/\[\s*(\d+)\./; if ($1 > '${START_TIME}') { print }' >> "$d/$p-dmesg" &
fi
local cnt=$(($OPT_RUN_TIME / $OPT_SLEEP_COLLECT))
if [ "$CMD_VMSTAT" ]; then
$CMD_VMSTAT $OPT_SLEEP_COLLECT $cnt >> "$d/$p-vmstat" &
$CMD_VMSTAT $OPT_RUN_TIME 2 >> "$d/$p-vmstat-overall" &
fi
if [ "$CMD_IOSTAT" ]; then
$CMD_IOSTAT -dx $OPT_SLEEP_COLLECT $cnt >> "$d/$p-iostat" &
$CMD_IOSTAT -dx $OPT_RUN_TIME 2 >> "$d/$p-iostat-overall" &
fi
if [ "$CMD_MPSTAT" ]; then
$CMD_MPSTAT -P ALL $OPT_SLEEP_COLLECT $cnt >> "$d/$p-mpstat" &
$CMD_MPSTAT -P ALL $OPT_RUN_TIME 1 >> "$d/$p-mpstat-overall" &
fi
$CMD_MYSQLADMIN $EXT_ARGV ext -i$OPT_SLEEP_COLLECT -c$cnt >>"$d/$p-mysqladmin" &
local mysqladmin_pid=$!
fi
local have_lock_waits_table=""
$CMD_MYSQL $EXT_ARGV -e "SHOW TABLES FROM INFORMATION_SCHEMA" \
| grep -i "INNODB_LOCK_WAITS" >/dev/null 2>&1
if [ $? -eq 0 ]; then
have_lock_waits_table="yes"
fi
log "Loop start: $(date +'TS %s.%N %F %T')"
local start_time=$(date +'%s')
local curr_time=$start_time
local ps_instrumentation_enabled=$($CMD_MYSQL $EXT_ARGV -e 'SELECT ENABLED FROM performance_schema.setup_instruments WHERE NAME = "transaction";' \
$CMD_MYSQLADMIN $EXT_ARGV ext -i$OPT_SLEEP_COLLECT -c$cnt >>"$d/$p-mysqladmin" &
mysqladmin_pid=$!
ps_instrumentation_enabled=$($CMD_MYSQL $EXT_ARGV -e 'SELECT ENABLED FROM performance_schema.setup_instruments WHERE NAME = "transaction";' \
| sed "2q;d" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')
if [ $ps_instrumentation_enabled != "yes" ]; then
log "Performance Schema instrumentation is disabled"
fi
}
while [ $((curr_time - start_time)) -lt $OPT_RUN_TIME ]; do
if [ ! "$OPT_MYSQL_ONLY" ]; then
disk_space $d > $d/$p-disk-space
check_disk_space \
$d/$p-disk-space \
"$OPT_DISK_BYTES_FREE" \
"$OPT_DISK_PCT_FREE" \
|| break
collect_system_data() {
ps -eaF >> "$d/$p-ps" &
top -bn${OPT_RUN_TIME} >> "$d/$p-top" &
sleep $(date +'%s.%N' | awk "{print $OPT_SLEEP_COLLECT - (\$1 % $OPT_SLEEP_COLLECT)}")
local ts="$(date +"TS %s.%N %F %T")"
[ "$mysqld_pid" ] && _lsof $mysqld_pid >> "$d/$p-lsof" &
if [ -d "/proc" ]; then
if [ -f "/proc/diskstats" ]; then
(echo $ts; cat /proc/diskstats) >> "$d/$p-diskstats" &
fi
if [ -f "/proc/stat" ]; then
(echo $ts; cat /proc/stat) >> "$d/$p-procstat" &
fi
if [ -f "/proc/vmstat" ]; then
(echo $ts; cat /proc/vmstat) >> "$d/$p-procvmstat" &
fi
if [ -f "/proc/meminfo" ]; then
(echo $ts; cat /proc/meminfo) >> "$d/$p-meminfo" &
fi
if [ -f "/proc/slabinfo" ]; then
(echo $ts; cat /proc/slabinfo) >> "$d/$p-slabinfo" &
fi
if [ -f "/proc/interrupts" ]; then
(echo $ts; cat /proc/interrupts) >> "$d/$p-interrupts" &
fi
fi
(echo $ts; df -k) >> "$d/$p-df" &
(echo $ts; netstat -antp) >> "$d/$p-netstat" &
(echo $ts; netstat -s) >> "$d/$p-netstat_s" &
if [ "$CMD_SYSCTL" ]; then
$CMD_SYSCTL -a >> "$d/$p-sysctl" &
fi
if [ "$CMD_DMESG" ]; then
local UPTIME=`cat /proc/uptime | awk '{ print $1 }'`
local START_TIME=$(echo "$UPTIME 60" | awk '{print ($1 - $2)}')
$CMD_DMESG | perl -ne 'm/\[\s*(\d+)\./; if ($1 > '${START_TIME}') { print }' >> "$d/$p-dmesg" &
fi
if [ "$CMD_VMSTAT" ]; then
$CMD_VMSTAT $OPT_SLEEP_COLLECT $cnt >> "$d/$p-vmstat" &
$CMD_VMSTAT $OPT_RUN_TIME 2 >> "$d/$p-vmstat-overall" &
fi
if [ "$CMD_IOSTAT" ]; then
$CMD_IOSTAT -dx $OPT_SLEEP_COLLECT $cnt >> "$d/$p-iostat" &
$CMD_IOSTAT -dx $OPT_RUN_TIME 2 >> "$d/$p-iostat-overall" &
fi
if [ "$CMD_MPSTAT" ]; then
$CMD_MPSTAT -P ALL $OPT_SLEEP_COLLECT $cnt >> "$d/$p-mpstat" &
$CMD_MPSTAT -P ALL $OPT_RUN_TIME 1 >> "$d/$p-mpstat-overall" &
fi
}
collect_mysql_data_loop() {
(echo $ts; $CMD_MYSQL $EXT_ARGV -e "SHOW FULL PROCESSLIST\G") \
>> "$d/$p-processlist" &
if [ "$have_lock_waits_table" ]; then
(echo $ts; lock_waits) >>"$d/$p-lock-waits" &
(echo $ts; transactions) >>"$d/$p-transactions" &
fi
if [ "${mysql_version}" '>' "5.6" ] && [ $ps_instrumentation_enabled == "yes" ]; then
ps_locks_transactions "$d/$p-ps-locks-transactions"
fi
if [ "${mysql_version}" '>' "5.6" ]; then
(echo $ts; ps_prepared_statements) >> "$d/$p-prepared-statements" &
fi
slave_status "$d/$p-slave-status" "${mysql_version}"
}
collect_system_data_loop() {
disk_space $d > $d/$p-disk-space
check_disk_space \
$d/$p-disk-space \
"$OPT_DISK_BYTES_FREE" \
"$OPT_DISK_PCT_FREE" \
|| break
sleep $(date +'%s.%N' | awk "{print $OPT_SLEEP_COLLECT - (\$1 % $OPT_SLEEP_COLLECT)}")
ts="$(date +"TS %s.%N %F %T")"
if [ -d "/proc" ]; then
if [ -f "/proc/diskstats" ]; then
(echo $ts; cat /proc/diskstats) >> "$d/$p-diskstats" &
fi
(echo $ts; $CMD_MYSQL $EXT_ARGV -e "SHOW FULL PROCESSLIST\G") \
>> "$d/$p-processlist" &
if [ "$have_lock_waits_table" ]; then
(echo $ts; lock_waits) >>"$d/$p-lock-waits" &
(echo $ts; transactions) >>"$d/$p-transactions" &
if [ -f "/proc/stat" ]; then
(echo $ts; cat /proc/stat) >> "$d/$p-procstat" &
fi
if [ "${mysql_version}" '>' "5.6" ] && [ $ps_instrumentation_enabled == "yes" ]; then
ps_locks_transactions "$d/$p-ps-locks-transactions"
if [ -f "/proc/vmstat" ]; then
(echo $ts; cat /proc/vmstat) >> "$d/$p-procvmstat" &
fi
if [ "${mysql_version}" '>' "5.6" ]; then
(echo $ts; ps_prepared_statements) >> "$d/$p-prepared-statements" &
if [ -f "/proc/meminfo" ]; then
(echo $ts; cat /proc/meminfo) >> "$d/$p-meminfo" &
fi
if [ -f "/proc/slabinfo" ]; then
(echo $ts; cat /proc/slabinfo) >> "$d/$p-slabinfo" &
fi
if [ -f "/proc/interrupts" ]; then
(echo $ts; cat /proc/interrupts) >> "$d/$p-interrupts" &
fi
fi
(echo $ts; df -k) >> "$d/$p-df" &
(echo $ts; netstat -antp) >> "$d/$p-netstat" &
(echo $ts; netstat -s) >> "$d/$p-netstat_s" &
}
slave_status "$d/$p-slave-status" "${mysql_version}"
curr_time=$(date +'%s')
done
log "Loop end: $(date +'TS %s.%N %F %T')"
collect_mysql_data_two() {
if [ "$have_oprofile" ]; then
$CMD_OPCONTROL --stop
$CMD_OPCONTROL --dump
@@ -1020,20 +1074,9 @@ collect() {
$CMD_MYSQL $EXT_ARGV -e "$mutex" >> "$d/$p-mutex-status2" &
open_tables >> "$d/$p-opentables2" &
kill $mysqladmin_pid
[ "$mysqladmin_pid" ] && kill $mysqladmin_pid
[ "$tail_error_log_pid" ] && kill $tail_error_log_pid
[ "$tcpdump_pid" ] && kill $tcpdump_pid
hostname > "$d/$p-hostname"
wait_for_subshells $OPT_RUN_TIME
kill_all_subshells
for file in "$d/$p-"*; do
if [ -z "$(grep -v '^TS ' --max-count 10 "$file")" ]; then
log "Removing empty file $file";
rm "$file"
fi
done
}
open_tables() {
@@ -1087,8 +1130,13 @@ transactions() {
tokudb_status() {
local n=$1
$CMD_MYSQL $EXT_ARGV -e "SHOW ENGINE TOKUDB STATUS\G" \
>> "$d/$p-tokudbstatus$n" || rm -f "$d/$p-tokudbstatus$n"
has_tokudb=`$CMD_MYSQL $EXT_ARGV -e "SHOW ENGINES" | grep -i 'tokudb'`
exit_code=$?
if [ $exit_code -eq 0 ]; then
$CMD_MYSQL $EXT_ARGV -e "SHOW ENGINE TOKUDB STATUS\G" \
>> "$d/$p-tokudbstatus$n" || rm -f "$d/$p-tokudbstatus$n"
fi
}
innodb_status() {
@@ -1171,11 +1219,11 @@ slave_status() {
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
sql="SELECT * FROM replication_connection_status\G"
sql="SELECT * FROM performance_schema.replication_connection_status\G"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
sql="SELECT * FROM replication_applier_status JOIN replication_applier_status_by_coordinator USING(channel_name)\G"
sql="SELECT * FROM performance_schema.replication_applier_status JOIN performance_schema.replication_applier_status_by_coordinator USING(channel_name)\G"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
fi
@@ -1452,6 +1500,7 @@ stalk() {
# ##################################################################
log "Collect $ITER triggered"
log "MYSQL_ONLY: $OPT_MYSQL_ONLY"
log "SYSTEM_ONLY: $OPT_SYSTEM_ONLY"
# Send email to whomever that collect has been triggered.
if [ "$OPT_NOTIFY_BY_EMAIL" ]; then
@@ -1468,6 +1517,8 @@ stalk() {
if [ -n "$last_prefix" ]; then
margin=$(du -mc "$OPT_DEST"/"$last_prefix"-* | tail -n 1 | awk '{print $1'})
fi
# Disk space checked even if system data collection is OFF
# See https://jira.percona.com/browse/PT-1486
disk_space "$OPT_DEST" > "$OPT_DEST/$prefix-disk-space"
check_disk_space \
"$OPT_DEST/$prefix-disk-space" \
@@ -1633,18 +1684,20 @@ if [ "${0##*/}" = "$TOOL" ] \
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,
# just error and exit.
[ -n "$(mysql --help)" ] \
|| die "Cannot execute mysql. Check that it is in PATH."
[ -n "$(mysqladmin --help)" ] \
|| die "Cannot execute mysqladmin. Check that it is in PATH."
if [ ! "$OPT_SYSTEM_ONLY" ]; then
# 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.
[ -n "$(mysql --help)" ] \
|| die "Cannot execute mysql. Check that it is in PATH."
[ -n "$(mysqladmin --help)" ] \
|| die "Cannot execute mysqladmin. Check that it is in PATH."
# Now that we have the cmd line opts, check that we can actually
# connect to MySQL.
[ -n "$(mysql $EXT_ARGV -e 'SELECT 1')" ] \
|| die "Cannot connect to MySQL. Check that MySQL is running and that the options after -- are correct."
# Now that we have the cmd line opts, check that we can actually
# connect to MySQL.
[ -n "$(mysql $EXT_ARGV -e 'SELECT 1')" ] \
|| die "Cannot connect to MySQL. Check that MySQL is running and that the options after -- are correct."
fi
# Check existence and access to the --dest dir if we're collecting.
if [ "$OPT_COLLECT" ]; then
@@ -2236,6 +2289,10 @@ L<"--disk-pct-free">, are still respected.
See also L<"--collect">.
=item --system-only
Trigger only operating system related captures, ignoring all others.
=item --threshold
type: int; default: 25

View File

@@ -9386,6 +9386,7 @@ use Percona::Toolkit;
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
use sigtrap 'handler', \&sig_int, 'normal-signals';
binmode(STDOUT, "encoding(UTF-8)");
# Global variables. Only really essential variables should be here.
my $oktorun = 1;

View File

@@ -49,10 +49,77 @@ collect() {
local d="$1" # directory to save results in
local p="$2" # prefix for each result file
local mysqld_pid=""
local cnt=$(($OPT_RUN_TIME / $OPT_SLEEP_COLLECT))
if [ ! "$OPT_SYSTEM_ONLY" ]; then
local mysqld_pid=""
local mysql_version=""
local mysql_error_log=""
local tail_error_log_pid=""
local have_lock_waits_table=""
local have_oprofile=""
local mysqladmin_pid=""
local mutex=""
local tcpdump_pid=""
local ps_instrumentation_enabled=""
collect_mysql_data_one
fi
# Grab a few general things first. Background all of these so we can start
# them all up as quickly as possible.
if [ ! "$OPT_MYSQL_ONLY" ]; then
collect_system_data
fi
# This loop gathers data for the rest of the duration, and defines the time
# of the whole job.
log "Loop start: $(date +'TS %s.%N %F %T')"
local start_time=$(date +'%s')
local curr_time=$start_time
local ts="$(date +"TS %s.%N %F %T")"
while [ $((curr_time - start_time)) -lt $OPT_RUN_TIME ]; do
if [ ! "$OPT_MYSQL_ONLY" ]; then
collect_system_data_loop
fi
if [ ! "$OPT_SYSTEM_ONLY" ]; then
collect_mysql_data_loop
fi
curr_time=$(date +'%s')
done
log "Loop end: $(date +'TS %s.%N %F %T')"
if [ ! "$OPT_SYSTEM_ONLY" ]; then
collect_mysql_data_two
fi
# Finally, record what system we collected this data from.
hostname > "$d/$p-hostname"
# Remove "empty" files, i.e. ones that are truly empty or
# just contain timestamp lines. When a command above fails,
# it may leave an empty file. But first wait another --run-time
# seconds for any slow process to finish:
# https://bugs.launchpad.net/percona-toolkit/+bug/1047701
wait_for_subshells $OPT_RUN_TIME
kill_all_subshells
for file in "$d/$p-"*; do
# If there's not at least 1 line that's not a TS,
# then the file is empty.
if [ -z "$(grep -v '^TS ' --max-count 10 "$file")" ]; then
log "Removing empty file $file";
rm "$file"
fi
done
}
collect_mysql_data_one() {
# Get pidof mysqld.
if [ ! "$OPT_MYSQL_ONLY" ]; then
port=$(mysql -ss -e 'SELECT @@port')
port=$($CMD_MYSQL $EXT_ARGV -ss -e 'SELECT @@port')
mysqld_pid=$(lsof -i ":${port}" | grep -i listen | cut -f 3 -d" ")
fi
@@ -84,16 +151,16 @@ collect() {
# Get the major.minor version number. Version 3.23 doesn't matter for our
# purposes, and other releases have x.x.x* version conventions so far.
local mysql_version="$(awk '/^version[^_]/{print substr($2,1,3)}' "$d/$p-variables")"
mysql_version="$(awk '/^version[^_]/{print substr($2,1,3)}' "$d/$p-variables")"
# Is MySQL logging its errors to a file? If so, tail that file.
local mysql_error_log="$(awk '/^log_error/{print $2}' "$d/$p-variables")"
mysql_error_log="$(awk '/^log_error\s/{print $2}' "$d/$p-variables")"
if [ -z "$mysql_error_log" -a "$mysqld_pid" ]; then
log $mysqld_pid
# Try getting it from the open filehandle...
mysql_error_log="$(ls -l /proc/$mysqld_pid/fd | awk '/ 2 ->/{print $NF}')"
fi
local tail_error_log_pid=""
if [ "$mysql_error_log" -a ! "$OPT_MYSQL_ONLY" ]; then
log "The MySQL error log seems to be $mysql_error_log"
tail -f "$mysql_error_log" >"$d/$p-log_error" &
@@ -101,16 +168,16 @@ collect() {
# Send a mysqladmin debug to the server so we can potentially learn about
# locking etc.
$CMD_MYSQLADMIN $EXT_ARGV debug
$CMD_MYSQLADMIN $EXT_ARGV
else
log "Could not find the MySQL error log"
fi
# Get a sample of these right away, so we can get these without interaction
# with the other commands we're about to run.
if [ "${mysql_version}" '>' "5.1" ]; then
local mutex="SHOW ENGINE INNODB MUTEX"
mutex="SHOW ENGINE INNODB MUTEX"
else
local mutex="SHOW MUTEX STATUS"
mutex="SHOW MUTEX STATUS"
fi
innodb_status 1
tokudb_status 1
@@ -120,7 +187,6 @@ collect() {
open_tables >> "$d/$p-opentables1" &
# If TCP dumping is specified, start that on the server's port.
local tcpdump_pid=""
if [ "$CMD_TCPDUMP" -a "$OPT_COLLECT_TCPDUMP" ]; then
local port=$(awk '/^port/{print $2}' "$d/$p-variables")
if [ "$port" ]; then
@@ -131,7 +197,6 @@ collect() {
# Next, start oprofile gathering data during the whole rest of this process.
# The --init should be a no-op if it has already been init-ed.
local have_oprofile=""
if [ "$CMD_OPCONTROL" -a "$OPT_COLLECT_OPROFILE" ]; then
if $CMD_OPCONTROL --init; then
$CMD_OPCONTROL --start --no-vmlinux
@@ -143,132 +208,123 @@ collect() {
local strace_pid=$!
fi
# Grab a few general things first. Background all of these so we can start
# them all up as quickly as possible.
if [ ! "$OPT_MYSQL_ONLY" ]; then
ps -eaF >> "$d/$p-ps" &
top -bn${OPT_RUN_TIME} >> "$d/$p-top" &
[ "$mysqld_pid" ] && _lsof $mysqld_pid >> "$d/$p-lsof" &
if [ "$CMD_SYSCTL" ]; then
$CMD_SYSCTL -a >> "$d/$p-sysctl" &
fi
# collect dmesg events from 60 seconds ago until present
if [ "$CMD_DMESG" ]; then
local UPTIME=`cat /proc/uptime | awk '{ print $1 }'`
local START_TIME=$(echo "$UPTIME 60" | awk '{print ($1 - $2)}')
$CMD_DMESG | perl -ne 'm/\[\s*(\d+)\./; if ($1 > '${START_TIME}') { print }' >> "$d/$p-dmesg" &
fi
local cnt=$(($OPT_RUN_TIME / $OPT_SLEEP_COLLECT))
if [ "$CMD_VMSTAT" ]; then
$CMD_VMSTAT $OPT_SLEEP_COLLECT $cnt >> "$d/$p-vmstat" &
$CMD_VMSTAT $OPT_RUN_TIME 2 >> "$d/$p-vmstat-overall" &
fi
if [ "$CMD_IOSTAT" ]; then
$CMD_IOSTAT -dx $OPT_SLEEP_COLLECT $cnt >> "$d/$p-iostat" &
$CMD_IOSTAT -dx $OPT_RUN_TIME 2 >> "$d/$p-iostat-overall" &
fi
if [ "$CMD_MPSTAT" ]; then
$CMD_MPSTAT -P ALL $OPT_SLEEP_COLLECT $cnt >> "$d/$p-mpstat" &
$CMD_MPSTAT -P ALL $OPT_RUN_TIME 1 >> "$d/$p-mpstat-overall" &
fi
# Collect multiple snapshots of the status variables. We use
# mysqladmin -c even though it is buggy and won't stop on its
# own in 5.1 and newer, because there is a chance that we will
# get and keep a connection to the database; in troubled times
# the database tends to exceed max_connections, so reconnecting
# in the loop tends not to work very well.
$CMD_MYSQLADMIN $EXT_ARGV ext -i$OPT_SLEEP_COLLECT -c$cnt >>"$d/$p-mysqladmin" &
local mysqladmin_pid=$!
fi
local have_lock_waits_table=""
$CMD_MYSQL $EXT_ARGV -e "SHOW TABLES FROM INFORMATION_SCHEMA" \
| grep -i "INNODB_LOCK_WAITS" >/dev/null 2>&1
if [ $? -eq 0 ]; then
have_lock_waits_table="yes"
fi
# This loop gathers data for the rest of the duration, and defines the time
# of the whole job.
log "Loop start: $(date +'TS %s.%N %F %T')"
local start_time=$(date +'%s')
local curr_time=$start_time
local ps_instrumentation_enabled=$($CMD_MYSQL $EXT_ARGV -e 'SELECT ENABLED FROM performance_schema.setup_instruments WHERE NAME = "transaction";' \
# Collect multiple snapshots of the status variables. We use
# mysqladmin -c even though it is buggy and won't stop on its
# own in 5.1 and newer, because there is a chance that we will
# get and keep a connection to the database; in troubled times
# the database tends to exceed max_connections, so reconnecting
# in the loop tends not to work very well.
$CMD_MYSQLADMIN $EXT_ARGV ext -i$OPT_SLEEP_COLLECT -c$cnt >>"$d/$p-mysqladmin" &
mysqladmin_pid=$!
ps_instrumentation_enabled=$($CMD_MYSQL $EXT_ARGV -e 'SELECT ENABLED FROM performance_schema.setup_instruments WHERE NAME = "transaction";' \
| sed "2q;d" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')
if [ $ps_instrumentation_enabled != "yes" ]; then
log "Performance Schema instrumentation is disabled"
fi
}
while [ $((curr_time - start_time)) -lt $OPT_RUN_TIME ]; do
if [ ! "$OPT_MYSQL_ONLY" ]; then
# We check the disk, but don't exit, because we need to stop jobs if we
# need to exit.
disk_space $d > $d/$p-disk-space
check_disk_space \
$d/$p-disk-space \
"$OPT_DISK_BYTES_FREE" \
"$OPT_DISK_PCT_FREE" \
|| break
collect_system_data() {
ps -eaF >> "$d/$p-ps" &
top -bn${OPT_RUN_TIME} >> "$d/$p-top" &
# Sleep between collect cycles.
# Synchronize ourselves onto the clock tick, so the sleeps are 1-second
sleep $(date +'%s.%N' | awk "{print $OPT_SLEEP_COLLECT - (\$1 % $OPT_SLEEP_COLLECT)}")
local ts="$(date +"TS %s.%N %F %T")"
[ "$mysqld_pid" ] && _lsof $mysqld_pid >> "$d/$p-lsof" &
# #####################################################################
# Collect data for this cycle.
# #####################################################################
if [ -d "/proc" ]; then
if [ -f "/proc/diskstats" ]; then
(echo $ts; cat /proc/diskstats) >> "$d/$p-diskstats" &
fi
if [ -f "/proc/stat" ]; then
(echo $ts; cat /proc/stat) >> "$d/$p-procstat" &
fi
if [ -f "/proc/vmstat" ]; then
(echo $ts; cat /proc/vmstat) >> "$d/$p-procvmstat" &
fi
if [ -f "/proc/meminfo" ]; then
(echo $ts; cat /proc/meminfo) >> "$d/$p-meminfo" &
fi
if [ -f "/proc/slabinfo" ]; then
(echo $ts; cat /proc/slabinfo) >> "$d/$p-slabinfo" &
fi
if [ -f "/proc/interrupts" ]; then
(echo $ts; cat /proc/interrupts) >> "$d/$p-interrupts" &
fi
fi
(echo $ts; df -k) >> "$d/$p-df" &
(echo $ts; netstat -antp) >> "$d/$p-netstat" &
(echo $ts; netstat -s) >> "$d/$p-netstat_s" &
if [ "$CMD_SYSCTL" ]; then
$CMD_SYSCTL -a >> "$d/$p-sysctl" &
fi
# collect dmesg events from 60 seconds ago until present
if [ "$CMD_DMESG" ]; then
local UPTIME=`cat /proc/uptime | awk '{ print $1 }'`
local START_TIME=$(echo "$UPTIME 60" | awk '{print ($1 - $2)}')
$CMD_DMESG | perl -ne 'm/\[\s*(\d+)\./; if ($1 > '${START_TIME}') { print }' >> "$d/$p-dmesg" &
fi
if [ "$CMD_VMSTAT" ]; then
$CMD_VMSTAT $OPT_SLEEP_COLLECT $cnt >> "$d/$p-vmstat" &
$CMD_VMSTAT $OPT_RUN_TIME 2 >> "$d/$p-vmstat-overall" &
fi
if [ "$CMD_IOSTAT" ]; then
$CMD_IOSTAT -dx $OPT_SLEEP_COLLECT $cnt >> "$d/$p-iostat" &
$CMD_IOSTAT -dx $OPT_RUN_TIME 2 >> "$d/$p-iostat-overall" &
fi
if [ "$CMD_MPSTAT" ]; then
$CMD_MPSTAT -P ALL $OPT_SLEEP_COLLECT $cnt >> "$d/$p-mpstat" &
$CMD_MPSTAT -P ALL $OPT_RUN_TIME 1 >> "$d/$p-mpstat-overall" &
fi
}
collect_mysql_data_loop() {
(echo $ts; $CMD_MYSQL $EXT_ARGV -e "SHOW FULL PROCESSLIST\G") \
>> "$d/$p-processlist" &
if [ "$have_lock_waits_table" ]; then
(echo $ts; lock_waits) >>"$d/$p-lock-waits" &
(echo $ts; transactions) >>"$d/$p-transactions" &
fi
if [ "${mysql_version}" '>' "5.6" ] && [ $ps_instrumentation_enabled == "yes" ]; then
ps_locks_transactions "$d/$p-ps-locks-transactions"
fi
if [ "${mysql_version}" '>' "5.6" ]; then
(echo $ts; ps_prepared_statements) >> "$d/$p-prepared-statements" &
fi
slave_status "$d/$p-slave-status" "${mysql_version}"
}
collect_system_data_loop() {
# We check the disk, but don't exit, because we need to stop jobs if we
# need to exit.
disk_space $d > $d/$p-disk-space
check_disk_space \
$d/$p-disk-space \
"$OPT_DISK_BYTES_FREE" \
"$OPT_DISK_PCT_FREE" \
|| break
# Sleep between collect cycles.
# Synchronize ourselves onto the clock tick, so the sleeps are 1-second
sleep $(date +'%s.%N' | awk "{print $OPT_SLEEP_COLLECT - (\$1 % $OPT_SLEEP_COLLECT)}")
ts="$(date +"TS %s.%N %F %T")"
# #####################################################################
# Collect data for this cycle.
# #####################################################################
if [ -d "/proc" ]; then
if [ -f "/proc/diskstats" ]; then
(echo $ts; cat /proc/diskstats) >> "$d/$p-diskstats" &
fi
(echo $ts; $CMD_MYSQL $EXT_ARGV -e "SHOW FULL PROCESSLIST\G") \
>> "$d/$p-processlist" &
if [ "$have_lock_waits_table" ]; then
(echo $ts; lock_waits) >>"$d/$p-lock-waits" &
(echo $ts; transactions) >>"$d/$p-transactions" &
if [ -f "/proc/stat" ]; then
(echo $ts; cat /proc/stat) >> "$d/$p-procstat" &
fi
if [ "${mysql_version}" '>' "5.6" ] && [ $ps_instrumentation_enabled == "yes" ]; then
ps_locks_transactions "$d/$p-ps-locks-transactions"
if [ -f "/proc/vmstat" ]; then
(echo $ts; cat /proc/vmstat) >> "$d/$p-procvmstat" &
fi
if [ "${mysql_version}" '>' "5.6" ]; then
(echo $ts; ps_prepared_statements) >> "$d/$p-prepared-statements" &
if [ -f "/proc/meminfo" ]; then
(echo $ts; cat /proc/meminfo) >> "$d/$p-meminfo" &
fi
if [ -f "/proc/slabinfo" ]; then
(echo $ts; cat /proc/slabinfo) >> "$d/$p-slabinfo" &
fi
if [ -f "/proc/interrupts" ]; then
(echo $ts; cat /proc/interrupts) >> "$d/$p-interrupts" &
fi
fi
(echo $ts; df -k) >> "$d/$p-df" &
(echo $ts; netstat -antp) >> "$d/$p-netstat" &
(echo $ts; netstat -s) >> "$d/$p-netstat_s" &
}
slave_status "$d/$p-slave-status" "${mysql_version}"
curr_time=$(date +'%s')
done
log "Loop end: $(date +'TS %s.%N %F %T')"
collect_mysql_data_two() {
if [ "$have_oprofile" ]; then
$CMD_OPCONTROL --stop
$CMD_OPCONTROL --dump
@@ -316,28 +372,9 @@ collect() {
open_tables >> "$d/$p-opentables2" &
# Kill backgrounded tasks.
kill $mysqladmin_pid
[ "$mysqladmin_pid" ] && kill $mysqladmin_pid
[ "$tail_error_log_pid" ] && kill $tail_error_log_pid
[ "$tcpdump_pid" ] && kill $tcpdump_pid
# Finally, record what system we collected this data from.
hostname > "$d/$p-hostname"
# Remove "empty" files, i.e. ones that are truly empty or
# just contain timestamp lines. When a command above fails,
# it may leave an empty file. But first wait another --run-time
# seconds for any slow process to finish:
# https://bugs.launchpad.net/percona-toolkit/+bug/1047701
wait_for_subshells $OPT_RUN_TIME
kill_all_subshells
for file in "$d/$p-"*; do
# If there's not at least 1 line that's not a TS,
# then the file is empty.
if [ -z "$(grep -v '^TS ' --max-count 10 "$file")" ]; then
log "Removing empty file $file";
rm "$file"
fi
done
}
open_tables() {
@@ -391,8 +428,13 @@ transactions() {
tokudb_status() {
local n=$1
$CMD_MYSQL $EXT_ARGV -e "SHOW ENGINE TOKUDB STATUS\G" \
>> "$d/$p-tokudbstatus$n" || rm -f "$d/$p-tokudbstatus$n"
has_tokudb=`$CMD_MYSQL $EXT_ARGV -e "SHOW ENGINES" | grep -i 'tokudb'`
exit_code=$?
if [ $exit_code -eq 0 ]; then
$CMD_MYSQL $EXT_ARGV -e "SHOW ENGINE TOKUDB STATUS\G" \
>> "$d/$p-tokudbstatus$n" || rm -f "$d/$p-tokudbstatus$n"
fi
}
innodb_status() {
@@ -475,11 +517,11 @@ slave_status() {
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
sql="SELECT * FROM replication_connection_status\G"
sql="SELECT * FROM performance_schema.replication_connection_status\G"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
sql="SELECT * FROM replication_applier_status JOIN replication_applier_status_by_coordinator USING(channel_name)\G"
sql="SELECT * FROM performance_schema.replication_applier_status JOIN performance_schema.replication_applier_status_by_coordinator USING(channel_name)\G"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
fi

View File

@@ -542,13 +542,13 @@ $retval = system("$trunk/bin/pt-stalk --no-stalk --run-time 2 --sleep 2 --dest $
PerconaTest::wait_until(sub { !-f $pid_file });
$output = `du -s $dest | wc -l`;
$output = `ls -l $dest | wc -l`;
$retval = system("$trunk/bin/pt-stalk --no-stalk --run-time 2 --dest $dest --retention-count 1 --pid $pid_file --iterations 1 -- --defaults-file=$cnf >$log_file 2>&1");
PerconaTest::wait_until(sub { !-f $pid_file });
$output = $output - `du -s $dest | wc -l`;
$output = $output - `ls -l $dest | wc -l`;
is(
$output,
@@ -556,6 +556,73 @@ is(
"Retention test 5: retention by count works as expected"
);
# ###########################################################################
# Test if option --system-only works correctly
# ###########################################################################
cleanup();
$retval = system("$trunk/bin/pt-stalk --no-stalk --system-only --run-time 10 --sleep 2 --dest $dest --pid $pid_file --iterations 1 -- --defaults-file=$cnf >$log_file 2>&1");
PerconaTest::wait_until(sub { !-f $pid_file });
$output = `ls $dest`;
like(
$output,
qr/(df)|(meminfo)/,
"Option --system-only collects system data"
);
unlike(
$output,
qr/(innodbstatus)|(mysqladmin)/,
"Option --system-only does not collect MySQL data"
);
# ###########################################################################
# Test if option --mysql-only works correctly
# ###########################################################################
cleanup();
$retval = system("$trunk/bin/pt-stalk --no-stalk --mysql-only --run-time 10 --sleep 2 --dest $dest --pid $pid_file --iterations 1 -- --defaults-file=$cnf >$log_file 2>&1");
PerconaTest::wait_until(sub { !-f $pid_file });
$output = `ls $dest`;
unlike(
$output,
qr/(df)|(meminfo)/,
"Option --mysql-only does not collect system data"
);
like(
$output,
qr/(innodbstatus)|(mysqladmin)/,
"Option --mysql-only collects MySQL data"
);
# ###########################################################################
# Test if options --mysql-only and --system-only specified together,
# pt-stalk collects only disk-space, hostname, output, and trigger
# ###########################################################################
cleanup();
$retval = system("$trunk/bin/pt-stalk --no-stalk --mysql-only --system-only --run-time 10 --sleep 2 --dest $dest --pid $pid_file --iterations 1 --prefix test -- --defaults-file=$cnf >$log_file 2>&1");
PerconaTest::wait_until(sub { !-f $pid_file });
$output = `ls $dest`;
is(
$output,
"test-disk-space\ntest-hostname\ntest-output\ntest-trigger\n",
"If both options --mysql-only and --system-only are specified only essential collections are triggered"
);
# ###########################################################################
# Test report about performance schema transactions in MySQL 5.7+
# ###########################################################################

View File

@@ -72,19 +72,19 @@ replace_pkg_in_tool() {
if [ "$tool_lang" = "perl" ]; then
echo "# $pkg 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,
# with comments and its test file can be found in the GitHub repository at,
# lib/$pkg_file_base.pm
# t/lib/$pkg_file_base.t
# See https://launchpad.net/percona-toolkit for more information.
# See https://github.com/percona/percona-toolkit for more information.
# ###########################################################################
{" >> $tmp_file
else
echo "# $pkg 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,
# with comments and its test file can be found in the GitHub repository at,
# lib/bash/$pkg.sh
# t/lib/bash/$pkg.sh
# See https://launchpad.net/percona-toolkit for more information.
# See https://github.com/percona/percona-toolkit for more information.
# ###########################################################################
" >> $tmp_file
fi