PT-2289 - Allow pt-stalk do disable ps-lock-transactions data collection via parameter

- Implemented _should_skip function as was suggested
This commit is contained in:
Sveta Smirnova
2025-09-05 16:08:43 +03:00
parent 66d20ae6da
commit cdc24c10f0
3 changed files with 74 additions and 29 deletions
+34 -21
View File
@@ -971,7 +971,7 @@ collect_mysql_data_one() {
fi
fi
if ! [[ "${OPT_SKIP_COLLECTION[@]}" =~ "mysqladmin" ]]; then
if ! _should_skip "mysqladmin"; then
$CMD_MYSQLADMIN $EXT_ARGV ext -i$OPT_SLEEP_COLLECT -c$cnt >>"$d/$p-mysqladmin" &
mysqladmin_pid=$!
fi
@@ -1016,7 +1016,7 @@ collect_system_data() {
collect_mysql_data_loop() {
if ! [[ "${OPT_SKIP_COLLECTION[@]}" =~ "processlist" ]]; then
if ! _should_skip "processlist"; then
(echo $ts; $CMD_MYSQL $EXT_ARGV -e "SHOW FULL PROCESSLIST\G") \
>> "$d/$p-processlist" &
fi
@@ -1025,16 +1025,16 @@ collect_mysql_data_loop() {
>> "$d/$p-threads" &
if [ "$have_lock_waits_table" ]; then
if ! [[ "${OPT_SKIP_COLLECTION[@]}" =~ "lock-waits" ]]; then
if ! _should_skip "lock-waits"; then
(echo $ts; lock_waits "$d/lock_waits.running") >>"$d/$p-lock-waits" &
fi
if ! [[ "${OPT_SKIP_COLLECTION[@]}" =~ "transactions" ]]; then
if ! _should_skip "transactions"; then
(echo $ts; transactions) >>"$d/$p-transactions" &
fi
fi
if [ "${mysql_version}" '>' "5.6" ] && [ $ps_instrumentation_enabled == "yes" ] \
&& ! [[ "${OPT_SKIP_COLLECTION[@]}" =~ "ps-locks-transactions" ]]; then
&& ! _should_skip "ps-locks-transactions"; then
ps_locks_transactions "$d/$p-ps-locks-transactions"
fi
@@ -1261,7 +1261,7 @@ innodb_status() {
local innostat=""
if ! [[ "${OPT_SKIP_COLLECTION[@]}" =~ "innodbstatus" ]]; then
if ! _should_skip "innodbstatus"; then
$CMD_MYSQL $EXT_ARGV -e "SHOW /*!40100 ENGINE*/ INNODB STATUS\G" \
>> "$d/$p-innodbstatus$n"
grep "END OF INNODB" "$d/$p-innodbstatus$n" >/dev/null || {
@@ -1285,7 +1285,7 @@ rocksdb_status() {
has_rocksdb=`$CMD_MYSQL $EXT_ARGV -e "SHOW ENGINES" | grep -i 'rocksdb'`
exit_code=$?
if [ $exit_code -eq 0 ] && ! [[ "${OPT_SKIP_COLLECTION[@]}" =~ "rocksdbstatus" ]]; then
if [ $exit_code -eq 0 ] && ! _should_skip "rocksdbstatus"; then
$CMD_MYSQL $EXT_ARGV -e "SHOW ENGINE ROCKSDB STATUS\G" \
>> "$d/$p-rocksdbstatus$n" || rm -f "$d/$p-rocksdbstatus$n"
fi
@@ -1367,7 +1367,7 @@ collect_mysql_variables() {
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
if ! [[ "${OPT_SKIP_COLLECTION[@]}" =~ "thread-variables" ]]; then
if ! _should_skip "thread-variables"; then
sql="select * from performance_schema.variables_by_thread order by thread_id, variable_name;"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
@@ -1383,6 +1383,19 @@ collect_mysql_variables() {
}
_should_skip() {
local name=$1
for item in "${OPT_SKIP_COLLECTION[@]}"; do
echo $item >> /tmp/sveta
if [ "$item" == "$name" ]; then
return 0
fi
done
return 1
}
# ###########################################################################
# End collect package
# ###########################################################################
@@ -1740,19 +1753,6 @@ main() {
log 'Both options --system-only and --mysql-only specified, collecting only disk-space, hostname, output, and trigger metrics';
fi
if [ "$OPT_SKIP_COLLECTION" ]; then
local supported_skips=(ps-locks-transactions thread-variables innodbstatus lock-waits mysqladmin processlist rocksdbstatus transactions)
IFS=',' read -ra skips <<< "$OPT_SKIP_COLLECTION"
OPT_SKIP_COLLECTION=("${skips[*]}")
for skip in "${skips[@]}"; do
echo "$supported_skips" | grep -q "$skip"
if ! [[ " ${supported_skips[@]} " =~ " ${skip} " ]]; then
log "Invalid --skip-collection value: $skip, exiting."
exit 1
fi
done
fi
# Note: $$ is the parent's PID, but we're a child proc.
# Bash 4 has $BASHPID but we can't rely on that. Consequently,
# we don't know our own PID. See the usage of $! below.
@@ -1810,6 +1810,19 @@ if [ "${0##*/}" = "$TOOL" ] \
fi
fi
if [ "$OPT_SKIP_COLLECTION" ]; then
local supported_skips=(ps-locks-transactions thread-variables innodbstatus lock-waits mysqladmin processlist rocksdbstatus transactions)
IFS=',' read -ra skips <<< "$OPT_SKIP_COLLECTION"
OPT_SKIP_COLLECTION=("${skips[@]}")
for skip in "${skips[@]}"; do
echo "$supported_skips" | grep -q "$skip"
if ! [[ " ${supported_skips[@]} " =~ " ${skip} " ]]; then
log "Invalid --skip-collection value: $skip, exiting."
exit 1
fi
done
fi
if [ -z "$OPT_STALK" -a "$OPT_COLLECT" ]; then
# Not stalking; do immediate collect once.
OPT_CYCLES=0