mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-13 06:30:10 +00:00
Use which to get programs. Don't create file unless the program or file exists.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
# This program is copyright 2011 Percona Inc.
|
# This program is copyright 2011-2012 Percona Inc.
|
||||||
# Feedback and improvements are welcome.
|
# Feedback and improvements are welcome.
|
||||||
#
|
#
|
||||||
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
|
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||||
@@ -24,17 +24,17 @@
|
|||||||
set -u
|
set -u
|
||||||
|
|
||||||
# Global variables.
|
# Global variables.
|
||||||
CMD_GDB=${CMD_GDB:-"gdb"}
|
CMD_GDB="$(which gdb)"
|
||||||
CMD_IOSTAT=${CMD_IOSTAT:-"iostat"}
|
CMD_IOSTAT="$(which iostat)"
|
||||||
CMD_MPSTAT=${CMD_MPSTAT:-"mpstat"}
|
CMD_MPSTAT="$(which mpstat)"
|
||||||
CMD_MYSQL=${CMD_MSSQL:-"mysql"}
|
CMD_MYSQL="$(which mysql)"
|
||||||
CMD_MYSQLADMIN=${CMD_MYSQL_ADMIN:-"mysqladmin"}
|
CMD_MYSQLADMIN="$(which mysqladmin)"
|
||||||
CMD_OPCONTROL=${CMD_OPCONTROL:-"opcontrol"}
|
CMD_OPCONTROL="$(which opcontrol)"
|
||||||
CMD_OPREPORT=${CMD_OPREPORT:-"opreport"}
|
CMD_OPREPORT="$(which opreport)"
|
||||||
CMD_PMAP=${CMD_PMAP:-"pmap"}
|
CMD_PMAP="$(which pmap)"
|
||||||
CMD_STRACE=${CMD_STRACE:-"strace"}
|
CMD_STRACE="$(which strace)"
|
||||||
CMD_TCPDUMP=${CMD_TCPDUMP:-"tcpdump"}
|
CMD_TCPDUMP="$(which tcpdump)"
|
||||||
CMD_VMSTAT=${CMD_VMSTAT:-"vmstat"}
|
CMD_VMSTAT="$(which vmstat)"
|
||||||
|
|
||||||
collect() {
|
collect() {
|
||||||
local d="$1" # directory to save results in
|
local d="$1" # directory to save results in
|
||||||
@@ -50,7 +50,7 @@ collect() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Get memory allocation info before anything else.
|
# Get memory allocation info before anything else.
|
||||||
if [ "$mysqld_pid" ]; then
|
if [ "$CMD_PMAP" -a "$mysqld_pid" ]; then
|
||||||
if $CMD_PMAP --help 2>&1 | grep -- -x >/dev/null 2>&1 ; then
|
if $CMD_PMAP --help 2>&1 | grep -- -x >/dev/null 2>&1 ; then
|
||||||
$CMD_PMAP -x $mysqld_pid > "$d/$p-pmap"
|
$CMD_PMAP -x $mysqld_pid > "$d/$p-pmap"
|
||||||
else
|
else
|
||||||
@@ -60,15 +60,13 @@ collect() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Getting a GDB stacktrace can be an intensive operation,
|
# Getting a GDB stacktrace can be an intensive operation,
|
||||||
# so do this only if necessary.
|
# so do this only if necessary (and possible).
|
||||||
if [ "$OPT_COLLECT_GDB" = "yes" -a "$mysqld_pid" ]; then
|
if [ "$CMD_GDB" -a "$OPT_COLLECT_GDB" = "yes" -a "$mysqld_pid" ]; then
|
||||||
$CMD_GDB \
|
$CMD_GDB \
|
||||||
-ex "set pagination 0" \
|
-ex "set pagination 0" \
|
||||||
-ex "thread apply all bt" \
|
-ex "thread apply all bt" \
|
||||||
--batch -p $mysqld_pid \
|
--batch -p $mysqld_pid \
|
||||||
>> "$d/$p-stacktrace"
|
>> "$d/$p-stacktrace"
|
||||||
else
|
|
||||||
echo "GDB (--collect-gdb) was not enabled" >> "$d/$p-stacktrace"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get MySQL's variables if possible. Then sleep long enough that we probably
|
# Get MySQL's variables if possible. Then sleep long enough that we probably
|
||||||
@@ -114,7 +112,7 @@ collect() {
|
|||||||
|
|
||||||
# If TCP dumping is specified, start that on the server's port.
|
# If TCP dumping is specified, start that on the server's port.
|
||||||
local tcpdump_pid=""
|
local tcpdump_pid=""
|
||||||
if [ "$OPT_COLLECT_TCPDUMP" = "yes" ]; then
|
if [ "$CMD_TCPDUMP" -a "$OPT_COLLECT_TCPDUMP" = "yes" ]; then
|
||||||
local port=$(awk '/^port/{print $2}' "$d/$p-variables")
|
local port=$(awk '/^port/{print $2}' "$d/$p-variables")
|
||||||
if [ "$port" ]; then
|
if [ "$port" ]; then
|
||||||
$CMD_TCPDUMP -i any -s 4096 -w "$d/$p-tcpdump" port ${port} &
|
$CMD_TCPDUMP -i any -s 4096 -w "$d/$p-tcpdump" port ${port} &
|
||||||
@@ -125,12 +123,12 @@ collect() {
|
|||||||
# Next, start oprofile gathering data during the whole rest of this process.
|
# 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.
|
# The --init should be a no-op if it has already been init-ed.
|
||||||
local have_oprofile="no"
|
local have_oprofile="no"
|
||||||
if [ "$OPT_COLLECT_OPROFILE" = "yes" ]; then
|
if [ "$CMD_OPCONTROL" -a "$OPT_COLLECT_OPROFILE" = "yes" ]; then
|
||||||
if $CMD_OPCONTROL --init; then
|
if $CMD_OPCONTROL --init; then
|
||||||
$CMD_OPCONTROL --start --no-vmlinux
|
$CMD_OPCONTROL --start --no-vmlinux
|
||||||
have_oprofile="yes"
|
have_oprofile="yes"
|
||||||
fi
|
fi
|
||||||
elif [ "$OPT_COLLECT_STRACE" = "yes" ]; then
|
elif [ "$CMD_STRACE" -a "$OPT_COLLECT_STRACE" = "yes" ]; then
|
||||||
# Don't run oprofile and strace at the same time.
|
# Don't run oprofile and strace at the same time.
|
||||||
$CMD_STRACE -T -s 0 -f -p $mysqld_pid > "${DEST}/$d-strace" 2>&1 &
|
$CMD_STRACE -T -s 0 -f -p $mysqld_pid > "${DEST}/$d-strace" 2>&1 &
|
||||||
local strace_pid=$!
|
local strace_pid=$!
|
||||||
@@ -141,13 +139,19 @@ collect() {
|
|||||||
ps -eaf >> "$d/$p-ps" 2>&1 &
|
ps -eaf >> "$d/$p-ps" 2>&1 &
|
||||||
sysctl -a >> "$d/$p-sysctl" 2>&1 &
|
sysctl -a >> "$d/$p-sysctl" 2>&1 &
|
||||||
top -bn1 >> "$d/$p-top" 2>&1 &
|
top -bn1 >> "$d/$p-top" 2>&1 &
|
||||||
|
lsof -nP -p $mysqld_pid -bw >> "$d/$p-lsof" 2>&1 &
|
||||||
|
if [ "$CMD_VMSTAT" ]; then
|
||||||
$CMD_VMSTAT 1 $OPT_INTERVAL >> "$d/$p-vmstat" 2>&1 &
|
$CMD_VMSTAT 1 $OPT_INTERVAL >> "$d/$p-vmstat" 2>&1 &
|
||||||
$CMD_VMSTAT $OPT_INTERVAL 2 >> "$d/$p-vmstat-overall" 2>&1 &
|
$CMD_VMSTAT $OPT_INTERVAL 2 >> "$d/$p-vmstat-overall" 2>&1 &
|
||||||
|
fi
|
||||||
|
if [ "$CMD_IOSTAT" ]; then
|
||||||
$CMD_IOSTAT -dx 1 $OPT_INTERVAL >> "$d/$p-iostat" 2>&1 &
|
$CMD_IOSTAT -dx 1 $OPT_INTERVAL >> "$d/$p-iostat" 2>&1 &
|
||||||
$CMD_IOSTAT -dx $OPT_INTERVAL 2 >> "$d/$p-iostat-overall" 2>&1 &
|
$CMD_IOSTAT -dx $OPT_INTERVAL 2 >> "$d/$p-iostat-overall" 2>&1 &
|
||||||
|
fi
|
||||||
|
if [ "$CMD_MPSTAT" ]; then
|
||||||
$CMD_MPSTAT -P ALL 1 $OPT_INTERVAL >> "$d/$p-mpstat" 2>&1 &
|
$CMD_MPSTAT -P ALL 1 $OPT_INTERVAL >> "$d/$p-mpstat" 2>&1 &
|
||||||
$CMD_MPSTAT -P ALL $OPT_INTERVAL 1 >> "$d/$p-mpstat-overall" 2>&1 &
|
$CMD_MPSTAT -P ALL $OPT_INTERVAL 1 >> "$d/$p-mpstat-overall" 2>&1 &
|
||||||
lsof -nP -p $mysqld_pid -bw >> "$d/$p-lsof" 2>&1 &
|
fi
|
||||||
|
|
||||||
# Collect multiple snapshots of the status variables. We use
|
# Collect multiple snapshots of the status variables. We use
|
||||||
# mysqladmin -c even though it is buggy and won't stop on its
|
# mysqladmin -c even though it is buggy and won't stop on its
|
||||||
@@ -183,12 +187,26 @@ collect() {
|
|||||||
local ts="$(date +"TS %s.%N %F %T")"
|
local ts="$(date +"TS %s.%N %F %T")"
|
||||||
|
|
||||||
# Collect the stuff for this cycle
|
# Collect the stuff for this cycle
|
||||||
|
if [ -d "/proc" ]; then
|
||||||
|
if [ -f "/proc/diskstats" ]; then
|
||||||
(cat /proc/diskstats 2>&1; echo $ts) >> "$d/$p-diskstats" &
|
(cat /proc/diskstats 2>&1; echo $ts) >> "$d/$p-diskstats" &
|
||||||
|
fi
|
||||||
|
if [ -f "/proc/stat" ]; then
|
||||||
(cat /proc/stat 2>&1; echo $ts) >> "$d/$p-procstat" &
|
(cat /proc/stat 2>&1; echo $ts) >> "$d/$p-procstat" &
|
||||||
|
fi
|
||||||
|
if [ -f "/proc/vmstat" ]; then
|
||||||
(cat /proc/vmstat 2>&1; echo $ts) >> "$d/$p-procvmstat" &
|
(cat /proc/vmstat 2>&1; echo $ts) >> "$d/$p-procvmstat" &
|
||||||
|
fi
|
||||||
|
if [ -f "/proc/meminfo" ]; then
|
||||||
(cat /proc/meminfo 2>&1; echo $ts) >> "$d/$p-meminfo" &
|
(cat /proc/meminfo 2>&1; echo $ts) >> "$d/$p-meminfo" &
|
||||||
|
fi
|
||||||
|
if [ -f "/proc/slabinfo" ]; then
|
||||||
(cat /proc/slabinfo 2>&1; echo $ts) >> "$d/$p-slabinfo" &
|
(cat /proc/slabinfo 2>&1; echo $ts) >> "$d/$p-slabinfo" &
|
||||||
|
fi
|
||||||
|
if [ -f "/proc/interrupts" ]; then
|
||||||
(cat /proc/interrupts 2>&1; echo $ts) >> "$d/$p-interrupts" &
|
(cat /proc/interrupts 2>&1; echo $ts) >> "$d/$p-interrupts" &
|
||||||
|
fi
|
||||||
|
fi
|
||||||
(df -h 2>&1; echo $ts) >> "$d/$p-df" &
|
(df -h 2>&1; echo $ts) >> "$d/$p-df" &
|
||||||
(netstat -antp 2>&1; echo $ts) >> "$d/$p-netstat" &
|
(netstat -antp 2>&1; echo $ts) >> "$d/$p-netstat" &
|
||||||
(netstat -s 2>&1; echo $ts) >> "$d/$p-netstat_s" &
|
(netstat -s 2>&1; echo $ts) >> "$d/$p-netstat_s" &
|
||||||
@@ -226,7 +244,7 @@ collect() {
|
|||||||
"/path/to/mysqld'" \
|
"/path/to/mysqld'" \
|
||||||
> "$d/$p-opreport"
|
> "$d/$p-opreport"
|
||||||
fi
|
fi
|
||||||
elif [ "$OPT_COLLECT_STRACE" = "yes" ]; then
|
elif [ "$CMD_STRACE" -a "$OPT_COLLECT_STRACE" = "yes" ]; then
|
||||||
kill -s 2 $strace_pid
|
kill -s 2 $strace_pid
|
||||||
sleep 1
|
sleep 1
|
||||||
kill -s 15 $strace_pid
|
kill -s 15 $strace_pid
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
TESTS=18
|
TESTS=19
|
||||||
|
|
||||||
TMPFILE="$TEST_TMPDIR/parse-opts-output"
|
TMPFILE="$TEST_TMPDIR/parse-opts-output"
|
||||||
TMPDIR="$TEST_TMPDIR"
|
TMPDIR="$TEST_TMPDIR"
|
||||||
@@ -23,12 +23,23 @@ local p="$TMPDIR/collect/2011_12_05"
|
|||||||
collect "$TMPDIR/collect" "2011_12_05" > $p-output 2>&1
|
collect "$TMPDIR/collect" "2011_12_05" > $p-output 2>&1
|
||||||
|
|
||||||
# Even if this system doesn't have all the cmds, collect should still
|
# Even if this system doesn't have all the cmds, collect should still
|
||||||
# create all the default files.
|
# have created some files for cmds that (hopefully) all systems have.
|
||||||
ls -1 $TMPDIR/collect | sort > $TMPDIR/collect-files
|
ls -1 $TMPDIR/collect | sort > $TMPDIR/collect-files
|
||||||
no_diff \
|
|
||||||
$TMPDIR/collect-files \
|
# If this system has /proc, then some files should be collected.
|
||||||
$T_LIB_DIR/samples/bash/collect001.txt \
|
# Else, those files should not exist.
|
||||||
"Default collect files"
|
if [ -f /proc/diskstats ]; then
|
||||||
|
cmd_ok \
|
||||||
|
"grep '[0-9]' $TMPDIR/collect/2011_12_05-diskstats" \
|
||||||
|
"/proc/diskstats"
|
||||||
|
else
|
||||||
|
test -f $TMPDIR/collect/2011_12_05-diskstats
|
||||||
|
is "$?" "1" "No /proc/diskstats"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cmd_ok \
|
||||||
|
"grep -q '\-hostname\$' $TMPDIR/collect-files" \
|
||||||
|
"Collected hostname"
|
||||||
|
|
||||||
cmd_ok \
|
cmd_ok \
|
||||||
"grep -q 'Avail' $p-df" \
|
"grep -q 'Avail' $p-df" \
|
||||||
|
@@ -1,34 +0,0 @@
|
|||||||
2011_12_05-df
|
|
||||||
2011_12_05-disk-space
|
|
||||||
2011_12_05-diskstats
|
|
||||||
2011_12_05-hostname
|
|
||||||
2011_12_05-innodbstatus1
|
|
||||||
2011_12_05-innodbstatus2
|
|
||||||
2011_12_05-interrupts
|
|
||||||
2011_12_05-iostat
|
|
||||||
2011_12_05-iostat-overall
|
|
||||||
2011_12_05-log_error
|
|
||||||
2011_12_05-lsof
|
|
||||||
2011_12_05-meminfo
|
|
||||||
2011_12_05-mpstat
|
|
||||||
2011_12_05-mpstat-overall
|
|
||||||
2011_12_05-mutex-status1
|
|
||||||
2011_12_05-mutex-status2
|
|
||||||
2011_12_05-mysqladmin
|
|
||||||
2011_12_05-netstat
|
|
||||||
2011_12_05-netstat_s
|
|
||||||
2011_12_05-opentables1
|
|
||||||
2011_12_05-opentables2
|
|
||||||
2011_12_05-output
|
|
||||||
2011_12_05-pmap
|
|
||||||
2011_12_05-processlist
|
|
||||||
2011_12_05-procstat
|
|
||||||
2011_12_05-procvmstat
|
|
||||||
2011_12_05-ps
|
|
||||||
2011_12_05-slabinfo
|
|
||||||
2011_12_05-stacktrace
|
|
||||||
2011_12_05-sysctl
|
|
||||||
2011_12_05-top
|
|
||||||
2011_12_05-variables
|
|
||||||
2011_12_05-vmstat
|
|
||||||
2011_12_05-vmstat-overall
|
|
Reference in New Issue
Block a user