mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
pt-mysql-summary: Make the "Instances" section work if the instances were started with --defaults-file
This commit is contained in:
@@ -1061,9 +1061,10 @@ parse_mysqld_instances () {
|
|||||||
local file="$1"
|
local file="$1"
|
||||||
local variables_file="$2"
|
local variables_file="$2"
|
||||||
|
|
||||||
local socket=${socket:-""}
|
local socket=""
|
||||||
local port=${port:-""}
|
local port=""
|
||||||
local datadir="${datadir:-""}"
|
local datadir=""
|
||||||
|
local defaults_file=""
|
||||||
|
|
||||||
[ -e "$file" ] || return
|
[ -e "$file" ] || return
|
||||||
|
|
||||||
@@ -1082,7 +1083,17 @@ parse_mysqld_instances () {
|
|||||||
if echo "${word}" | grep -- "--datadir=" > /dev/null; then
|
if echo "${word}" | grep -- "--datadir=" > /dev/null; then
|
||||||
datadir="$(echo "${word}" | cut -d= -f2)"
|
datadir="$(echo "${word}" | cut -d= -f2)"
|
||||||
fi
|
fi
|
||||||
|
if echo "${word}" | grep -- "--defaults-file=" > /dev/null; then
|
||||||
|
defaults_file="$(echo "${word}" | cut -d= -f2)"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ -n "${defaults_file:-""}" -a -r "${defaults_file:-""}" ]; then
|
||||||
|
socket="${socket:-"$(grep "^socket\>" "$defaults_file" | tail -n1 | cut -d= -f2 | sed 's/^[ \t]*//;s/[ \t]*$//')"}"
|
||||||
|
port="${port:-"$(grep "^port\>" "$defaults_file" | tail -n1 | cut -d= -f2 | sed 's/^[ \t]*//;s/[ \t]*$//')"}"
|
||||||
|
datadir="${datadir:-"$(grep "^datadir\>" "$defaults_file" | tail -n1 | cut -d= -f2 | sed 's/^[ \t]*//;s/[ \t]*$//')"}"
|
||||||
|
fi
|
||||||
|
|
||||||
local nice="$(get_var "internal::nice_of_$pid" "$variables_file")"
|
local nice="$(get_var "internal::nice_of_$pid" "$variables_file")"
|
||||||
local oom="$(get_var "internal::oom_of_$pid" "$variables_file")"
|
local oom="$(get_var "internal::oom_of_$pid" "$variables_file")"
|
||||||
if [ -n "${_NO_FALSE_NEGATIVES}" ]; then
|
if [ -n "${_NO_FALSE_NEGATIVES}" ]; then
|
||||||
@@ -1090,6 +1101,11 @@ parse_mysqld_instances () {
|
|||||||
oom="?"
|
oom="?"
|
||||||
fi
|
fi
|
||||||
printf " %5s %-26s %-4s %-3s %s\n" "${port}" "${datadir}" "${nice:-"?"}" "${oom:-"?"}" "${socket}"
|
printf " %5s %-26s %-4s %-3s %s\n" "${port}" "${datadir}" "${nice:-"?"}" "${oom:-"?"}" "${socket}"
|
||||||
|
|
||||||
|
defaults_file=""
|
||||||
|
socket=""
|
||||||
|
port=""
|
||||||
|
datadir=""
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -104,9 +104,10 @@ parse_mysqld_instances () {
|
|||||||
local file="$1"
|
local file="$1"
|
||||||
local variables_file="$2"
|
local variables_file="$2"
|
||||||
|
|
||||||
local socket=${socket:-""}
|
local socket=""
|
||||||
local port=${port:-""}
|
local port=""
|
||||||
local datadir="${datadir:-""}"
|
local datadir=""
|
||||||
|
local defaults_file=""
|
||||||
|
|
||||||
[ -e "$file" ] || return
|
[ -e "$file" ] || return
|
||||||
|
|
||||||
@@ -127,7 +128,17 @@ parse_mysqld_instances () {
|
|||||||
if echo "${word}" | grep -- "--datadir=" > /dev/null; then
|
if echo "${word}" | grep -- "--datadir=" > /dev/null; then
|
||||||
datadir="$(echo "${word}" | cut -d= -f2)"
|
datadir="$(echo "${word}" | cut -d= -f2)"
|
||||||
fi
|
fi
|
||||||
|
if echo "${word}" | grep -- "--defaults-file=" > /dev/null; then
|
||||||
|
defaults_file="$(echo "${word}" | cut -d= -f2)"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ -n "${defaults_file:-""}" -a -r "${defaults_file:-""}" ]; then
|
||||||
|
socket="${socket:-"$(grep "^socket\>" "$defaults_file" | tail -n1 | cut -d= -f2 | sed 's/^[ \t]*//;s/[ \t]*$//')"}"
|
||||||
|
port="${port:-"$(grep "^port\>" "$defaults_file" | tail -n1 | cut -d= -f2 | sed 's/^[ \t]*//;s/[ \t]*$//')"}"
|
||||||
|
datadir="${datadir:-"$(grep "^datadir\>" "$defaults_file" | tail -n1 | cut -d= -f2 | sed 's/^[ \t]*//;s/[ \t]*$//')"}"
|
||||||
|
fi
|
||||||
|
|
||||||
local nice="$(get_var "internal::nice_of_$pid" "$variables_file")"
|
local nice="$(get_var "internal::nice_of_$pid" "$variables_file")"
|
||||||
local oom="$(get_var "internal::oom_of_$pid" "$variables_file")"
|
local oom="$(get_var "internal::oom_of_$pid" "$variables_file")"
|
||||||
# Only used during testing
|
# Only used during testing
|
||||||
@@ -136,6 +147,12 @@ parse_mysqld_instances () {
|
|||||||
oom="?"
|
oom="?"
|
||||||
fi
|
fi
|
||||||
printf " %5s %-26s %-4s %-3s %s\n" "${port}" "${datadir}" "${nice:-"?"}" "${oom:-"?"}" "${socket}"
|
printf " %5s %-26s %-4s %-3s %s\n" "${port}" "${datadir}" "${nice:-"?"}" "${oom:-"?"}" "${socket}"
|
||||||
|
|
||||||
|
# Need to unset all of them in case the next process uses --defaults-file
|
||||||
|
defaults_file=""
|
||||||
|
socket=""
|
||||||
|
port=""
|
||||||
|
datadir=""
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
plan 33
|
plan 34
|
||||||
|
|
||||||
. "$LIB_DIR/alt_cmds.sh"
|
. "$LIB_DIR/alt_cmds.sh"
|
||||||
. "$LIB_DIR/log_warn_die.sh"
|
. "$LIB_DIR/log_warn_die.sh"
|
||||||
@@ -307,6 +307,16 @@ EOF
|
|||||||
parse_mysqld_instances "$PT_TMPDIR/in" "$PT_TMPDIR/empty" > "$PT_TMPDIR/got"
|
parse_mysqld_instances "$PT_TMPDIR/in" "$PT_TMPDIR/empty" > "$PT_TMPDIR/got"
|
||||||
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "parse_mysqld_instances"
|
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "parse_mysqld_instances"
|
||||||
|
|
||||||
|
cat <<EOF > "$PT_TMPDIR/expected"
|
||||||
|
Port Data Directory Nice OOM Socket
|
||||||
|
===== ========================== ==== === ======
|
||||||
|
12345 /tmp/12345/data ? ? /tmp/12345/mysql_sandbox12345.sock
|
||||||
|
12346 /tmp/12346/data ? ? /tmp/12346/mysql_sandbox12346.sock
|
||||||
|
12347 /tmp/12347/data ? ? /tmp/12347/mysql_sandbox12347.sock
|
||||||
|
EOF
|
||||||
|
parse_mysqld_instances "$samples/ps-mysqld-006.txt" "$PT_TMPDIR/empty" > "$PT_TMPDIR/got"
|
||||||
|
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "ps-mysqld-006.txt (uses --defaults-file)"
|
||||||
|
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
# get_mysql_*
|
# get_mysql_*
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
|
Reference in New Issue
Block a user