Tweak, fix, and add tests so every tool passes.

This commit is contained in:
Daniel Nichter
2011-08-02 16:38:03 -06:00
parent 1e6c4daf23
commit 747d63a6d3
13 changed files with 227 additions and 134 deletions

View File

@@ -50,7 +50,7 @@ fuzz () {
# symlink them to /etc/passwd and then run this program as root. Call this
# function with "rm" or "touch" as an argument.
temp_files() {
for file in /tmp/pt-summary.tmp /tmp/pt-summary.tmp2; do
for file in /tmp/percona-toolkit /tmp/percona-toolkit2; do
case "$1" in
touch)
if ! touch "${file}"; then
@@ -128,21 +128,21 @@ group_concat () {
# 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
# easily. The calling convention is that the data they need to run is prepared
# first by putting it into /tmp/pt-summary.tmp. Then code that's testing just needs to
# put sample data into /tmp/pt-summary.tmp and call it.
# first by putting it into /tmp/percona-toolkit. Then code that's testing just needs to
# put sample data into /tmp/percona-toolkit and call it.
# ##############################################################################
# ##############################################################################
# Parse Linux's /proc/cpuinfo, which should be stored in /tmp/pt-summary.tmp.
# Parse Linux's /proc/cpuinfo, which should be stored in /tmp/percona-toolkit.
# ##############################################################################
parse_proc_cpuinfo () {
# Physical processors are indicated by distinct 'physical id'. Virtual CPUs
# are indicated by paragraphs -- one per paragraph. We assume that all
# processors are identical, i.e. that there are not some processors with dual
# cores and some with quad cores.
virtual=$(grep -c ^processor /tmp/pt-summary.tmp);
physical=$(grep 'physical id' /tmp/pt-summary.tmp | sort -u | wc -l);
cores=$(grep 'cpu cores' /tmp/pt-summary.tmp | head -n 1 | cut -d: -f2);
virtual=$(grep -c ^processor /tmp/percona-toolkit);
physical=$(grep 'physical id' /tmp/percona-toolkit | sort -u | wc -l);
cores=$(grep 'cpu cores' /tmp/percona-toolkit | head -n 1 | cut -d: -f2);
# Older kernel won't have 'physical id' or 'cpu cores'.
if [ "${physical}" = "0" ]; then physical=${virtual}; fi
@@ -155,17 +155,17 @@ parse_proc_cpuinfo () {
name_val "Processors" "physical = ${physical}, cores = ${cores}, virtual = ${virtual}, hyperthreading = ${htt}"
awk -F: '/cpu MHz/{print $2}' /tmp/pt-summary.tmp \
| sort | uniq -c > /tmp/pt-summary.tmp2
name_val "Speeds" "$(group_concat /tmp/pt-summary.tmp2)"
awk -F: '/cpu MHz/{print $2}' /tmp/percona-toolkit \
| sort | uniq -c > /tmp/percona-toolkit2
name_val "Speeds" "$(group_concat /tmp/percona-toolkit2)"
awk -F: '/model name/{print $2}' /tmp/pt-summary.tmp \
| sort | uniq -c > /tmp/pt-summary.tmp2
name_val "Models" "$(group_concat /tmp/pt-summary.tmp2)"
awk -F: '/model name/{print $2}' /tmp/percona-toolkit \
| sort | uniq -c > /tmp/percona-toolkit2
name_val "Models" "$(group_concat /tmp/percona-toolkit2)"
awk -F: '/cache size/{print $2}' /tmp/pt-summary.tmp \
| sort | uniq -c > /tmp/pt-summary.tmp2
name_val "Caches" "$(group_concat /tmp/pt-summary.tmp2)"
awk -F: '/cache size/{print $2}' /tmp/percona-toolkit \
| sort | uniq -c > /tmp/percona-toolkit2
name_val "Caches" "$(group_concat /tmp/percona-toolkit2)"
}
# ##############################################################################
@@ -188,8 +188,8 @@ parse_psrinfo_cpus() {
start = index($0, " at ") + 4;
end = length($0) - start - 4
print substr($0, start, end);
}' "$1" | sort | uniq -c > /tmp/pt-summary.tmp2
name_val "Speeds" "$(group_concat /tmp/pt-summary.tmp2)"
}' "$1" | sort | uniq -c > /tmp/percona-toolkit2
name_val "Speeds" "$(group_concat /tmp/percona-toolkit2)"
}
# ##############################################################################
@@ -234,7 +234,7 @@ parse_memory_sysctl_freebsd() {
# ##############################################################################
# Parse memory devices from the output of 'dmidecode', which should be stored in
# /tmp/pt-summary.tmp.
# /tmp/percona-toolkit.
# ##############################################################################
parse_dmidecode_mem_devices () {
echo " Locator Size Speed Form Factor Type Type Detail"
@@ -254,7 +254,7 @@ parse_dmidecode_mem_devices () {
-e 's/</{/g' \
-e 's/>/}/g' \
-e 's/[ \t]*\n/\n/g' \
/tmp/pt-summary.tmp \
/tmp/percona-toolkit \
| awk -F: '/Size|Type|Form.Factor|Type.Detail|[^ ]Locator/{printf("|%s", $2)}/Speed/{print "|" $2}' \
| sed -e 's/No Module Installed/{EMPTY}/' \
| sort \
@@ -289,13 +289,13 @@ parse_ip_s_link () {
}
# ##############################################################################
# Parse the output of 'netstat -antp' which should be in /tmp/pt-summary.tmp.
# Parse the output of 'netstat -antp' which should be in /tmp/percona-toolkit.
# ##############################################################################
parse_netstat () {
echo " Connections from remote IP addresses"
awk '$1 ~ /^tcp/ && $5 ~ /^[1-9]/ {
print substr($5, 0, index($5, ":") - 1);
}' /tmp/pt-summary.tmp | sort | uniq -c \
}' /tmp/percona-toolkit | sort | uniq -c \
| awk "{
fuzzy_var=\$1;
${fuzzy_formula}
@@ -305,7 +305,7 @@ parse_netstat () {
echo " Connections to local IP addresses"
awk '$1 ~ /^tcp/ && $5 ~ /^[1-9]/ {
print substr($4, 0, index($4, ":") - 1);
}' /tmp/pt-summary.tmp | sort | uniq -c \
}' /tmp/percona-toolkit | sort | uniq -c \
| awk "{
fuzzy_var=\$1;
${fuzzy_formula}
@@ -315,7 +315,7 @@ parse_netstat () {
echo " Connections to top 10 local ports"
awk '$1 ~ /^tcp/ && $5 ~ /^[1-9]/ {
print substr($4, index($4, ":") + 1);
}' /tmp/pt-summary.tmp | sort | uniq -c | sort -rn | head -n10 \
}' /tmp/percona-toolkit | sort | uniq -c | sort -rn | head -n10 \
| awk "{
fuzzy_var=\$1;
${fuzzy_formula}
@@ -324,7 +324,7 @@ parse_netstat () {
echo " States of connections"
awk '$1 ~ /^tcp/ {
print $6;
}' /tmp/pt-summary.tmp | sort | uniq -c | sort -rn \
}' /tmp/percona-toolkit | sort | uniq -c | sort -rn \
| awk "{
fuzzy_var=\$1;
${fuzzy_formula}
@@ -394,7 +394,7 @@ parse_filesystems () {
}
# ##############################################################################
# Parse the output of fdisk -l, which should be in /tmp/pt-summary.tmp; there might be
# Parse the output of fdisk -l, which should be in /tmp/percona-toolkit; there might be
# multiple fdisk -l outputs in the file.
# ##############################################################################
parse_fdisk () {
@@ -423,25 +423,25 @@ parse_fdisk () {
}
printf(format, $1, "Part", start, end, sprintf("%.0f", (end - start) * units));
}
' /tmp/pt-summary.tmp
' /tmp/percona-toolkit
}
# ##############################################################################
# Parse the output of dmesg, which should be in /tmp/pt-summary.tmp, and detect
# Parse the output of dmesg, which should be in /tmp/percona-toolkit, and detect
# virtualization.
# ##############################################################################
parse_virtualization_dmesg () {
if grep -qi -e vmware -e vmxnet -e 'paravirtualized kernel on vmi' /tmp/pt-summary.tmp; then
if grep -qi -e vmware -e vmxnet -e 'paravirtualized kernel on vmi' /tmp/percona-toolkit; then
echo "VMWare";
elif grep -qi -e 'paravirtualized kernel on xen' -e 'Xen virtual console' /tmp/pt-summary.tmp; then
elif grep -qi -e 'paravirtualized kernel on xen' -e 'Xen virtual console' /tmp/percona-toolkit; then
echo "Xen";
elif grep -qi qemu /tmp/pt-summary.tmp; then
elif grep -qi qemu /tmp/percona-toolkit; then
echo "QEmu";
elif grep -qi 'paravirtualized kernel on KVM' /tmp/pt-summary.tmp; then
elif grep -qi 'paravirtualized kernel on KVM' /tmp/percona-toolkit; then
echo "KVM";
elif grep -q VBOX /tmp/pt-summary.tmp; then
elif grep -q VBOX /tmp/percona-toolkit; then
echo "VirtualBox";
elif grep -qi 'hd.: Virtual .., ATA.*drive' /tmp/pt-summary.tmp; then
elif grep -qi 'hd.: Virtual .., ATA.*drive' /tmp/percona-toolkit; then
echo "Microsoft VirtualPC";
fi
}
@@ -458,73 +458,73 @@ parse_virtualization_generic() {
}
# ##############################################################################
# Parse the output of lspci, which should be in /tmp/pt-summary.tmp, and detect
# Parse the output of lspci, which should be in /tmp/percona-toolkit, and detect
# Ethernet cards.
# ##############################################################################
parse_ethernet_controller_lspci () {
grep -i ethernet /tmp/pt-summary.tmp | cut -d: -f3 | while read line; do
grep -i ethernet /tmp/percona-toolkit | cut -d: -f3 | while read line; do
name_val Controller "${line}"
done
}
# ##############################################################################
# Parse the output of lspci, which should be in /tmp/pt-summary.tmp, and detect RAID
# Parse the output of lspci, which should be in /tmp/percona-toolkit, and detect RAID
# controllers.
# ##############################################################################
parse_raid_controller_lspci () {
if grep -q "RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS" /tmp/pt-summary.tmp; then
if grep -q "RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS" /tmp/percona-toolkit; then
echo 'LSI Logic MegaRAID SAS'
elif grep -q "Fusion-MPT SAS" /tmp/pt-summary.tmp; then
elif grep -q "Fusion-MPT SAS" /tmp/percona-toolkit; then
echo 'Fusion-MPT SAS'
elif grep -q "RAID bus controller: LSI Logic / Symbios Logic Unknown" /tmp/pt-summary.tmp; then
elif grep -q "RAID bus controller: LSI Logic / Symbios Logic Unknown" /tmp/percona-toolkit; then
echo 'LSI Logic Unknown'
elif grep -q "RAID bus controller: Adaptec AAC-RAID" /tmp/pt-summary.tmp; then
elif grep -q "RAID bus controller: Adaptec AAC-RAID" /tmp/percona-toolkit; then
echo 'AACRAID'
elif grep -q "3ware [0-9]* Storage Controller" /tmp/pt-summary.tmp; then
elif grep -q "3ware [0-9]* Storage Controller" /tmp/percona-toolkit; then
echo '3Ware'
elif grep -q "Hewlett-Packard Company Smart Array" /tmp/pt-summary.tmp; then
elif grep -q "Hewlett-Packard Company Smart Array" /tmp/percona-toolkit; then
echo 'HP Smart Array'
elif grep -q " RAID bus controller: " /tmp/pt-summary.tmp; then
awk -F: '/RAID bus controller\:/ {print $3" "$5" "$6}' /tmp/pt-summary.tmp
elif grep -q " RAID bus controller: " /tmp/percona-toolkit; then
awk -F: '/RAID bus controller\:/ {print $3" "$5" "$6}' /tmp/percona-toolkit
fi
}
# ##############################################################################
# Parse the output of dmesg, which should be in /tmp/pt-summary.tmp, and detect RAID
# Parse the output of dmesg, which should be in /tmp/percona-toolkit, and detect RAID
# controllers.
# ##############################################################################
parse_raid_controller_dmesg () {
pat='scsi[0-9].*: .*'
if grep -qi "${pat}megaraid" /tmp/pt-summary.tmp; then
if grep -qi "${pat}megaraid" /tmp/percona-toolkit; then
echo 'LSI Logic MegaRAID SAS'
elif grep -q "Fusion MPT SAS" /tmp/pt-summary.tmp; then
elif grep -q "Fusion MPT SAS" /tmp/percona-toolkit; then
echo 'Fusion-MPT SAS'
elif grep -q "${pat}aacraid" /tmp/pt-summary.tmp; then
elif grep -q "${pat}aacraid" /tmp/percona-toolkit; then
echo 'AACRAID'
elif grep -q "${pat}3ware [0-9]* Storage Controller" /tmp/pt-summary.tmp; then
elif grep -q "${pat}3ware [0-9]* Storage Controller" /tmp/percona-toolkit; then
echo '3Ware'
fi
}
# ##############################################################################
# Parse the output of "hpacucli ctrl all show config", which should be stored in
# /tmp/pt-summary.tmp
# /tmp/percona-toolkit
# ##############################################################################
parse_hpacucli () {
grep 'logicaldrive\|physicaldrive' /tmp/pt-summary.tmp
grep 'logicaldrive\|physicaldrive' /tmp/percona-toolkit
}
# ##############################################################################
# Parse the output of arcconf, which should be stored in /tmp/pt-summary.tmp
# Parse the output of arcconf, which should be stored in /tmp/percona-toolkit
# ##############################################################################
parse_arcconf () {
model=$(awk -F: '/Controller Model/{print $2}' /tmp/pt-summary.tmp)
chan="$(awk -F: '/Channel description/{print $2}' /tmp/pt-summary.tmp)"
cache="$(awk -F: '/Installed memory/{print $2}' /tmp/pt-summary.tmp)"
status="$(awk -F: '/Controller Status/{print $2}' /tmp/pt-summary.tmp)"
model=$(awk -F: '/Controller Model/{print $2}' /tmp/percona-toolkit)
chan="$(awk -F: '/Channel description/{print $2}' /tmp/percona-toolkit)"
cache="$(awk -F: '/Installed memory/{print $2}' /tmp/percona-toolkit)"
status="$(awk -F: '/Controller Status/{print $2}' /tmp/percona-toolkit)"
name_val Specs "${model/ /},${chan},${cache} cache,${status}"
battery=$(grep -A5 'Controller Battery Info' /tmp/pt-summary.tmp \
battery=$(grep -A5 'Controller Battery Info' /tmp/percona-toolkit \
| awk '/Capacity remaining/ {c=$4}
/Status/ {s=$3}
/Time remaining/ {t=sprintf("%dd%dh%dm", $7, $9, $11)}
@@ -537,9 +537,9 @@ parse_arcconf () {
echo
echo " LogicalDev Size RAID Disks Stripe Status Cache"
echo " ========== ========= ==== ===== ====== ======= ======="
for dev in $(awk '/Logical device number/{print $4}' /tmp/pt-summary.tmp); do
for dev in $(awk '/Logical device number/{print $4}' /tmp/percona-toolkit); do
sed -n -e "/^Logical device .* ${dev}$/,/^$\|^Logical device number/p" \
/tmp/pt-summary.tmp \
/tmp/percona-toolkit \
| awk '
/Logical device name/ {d=$5}
/Size/ {z=$3 " " $4}
@@ -565,7 +565,7 @@ parse_arcconf () {
# Find the paragraph with physical devices, tabularize with assoc arrays.
tempresult=""
sed -n -e '/Physical Device information/,/^$/p' /tmp/pt-summary.tmp \
sed -n -e '/Physical Device information/,/^$/p' /tmp/percona-toolkit \
| awk -F: '
/Device #[0-9]/ {
device=substr($0, index($0, "#"));
@@ -616,45 +616,45 @@ parse_arcconf () {
}
# ##############################################################################
# Parse the output of "lsiutil -i -s" from /tmp/pt-summary.tmp
# Parse the output of "lsiutil -i -s" from /tmp/percona-toolkit
# ##############################################################################
parse_fusionmpt_lsiutil () {
echo
awk '/LSI.*Firmware/ { print " ", $0 }' /tmp/pt-summary.tmp
grep . /tmp/pt-summary.tmp | sed -n -e '/B___T___L/,$ {s/^/ /; p}'
awk '/LSI.*Firmware/ { print " ", $0 }' /tmp/percona-toolkit
grep . /tmp/percona-toolkit | sed -n -e '/B___T___L/,$ {s/^/ /; p}'
}
# ##############################################################################
# Parse the output of MegaCli64 -AdpAllInfo -aALL from /tmp/pt-summary.tmp.
# Parse the output of MegaCli64 -AdpAllInfo -aALL from /tmp/percona-toolkit.
# ##############################################################################
parse_lsi_megaraid_adapter_info () {
name=$(awk -F: '/Product Name/{print substr($2, 2)}' /tmp/pt-summary.tmp);
int=$(awk '/Host Interface/{print $4}' /tmp/pt-summary.tmp);
prt=$(awk '/Number of Backend Port/{print $5}' /tmp/pt-summary.tmp);
bbu=$(awk '/^BBU :/{print $3}' /tmp/pt-summary.tmp);
mem=$(awk '/Memory Size/{print $4}' /tmp/pt-summary.tmp);
vdr=$(awk '/Virtual Drives/{print $4}' /tmp/pt-summary.tmp);
dvd=$(awk '/Degraded/{print $3}' /tmp/pt-summary.tmp);
phy=$(awk '/^ Disks/{print $3}' /tmp/pt-summary.tmp);
crd=$(awk '/Critical Disks/{print $4}' /tmp/pt-summary.tmp);
fad=$(awk '/Failed Disks/{print $4}' /tmp/pt-summary.tmp);
name=$(awk -F: '/Product Name/{print substr($2, 2)}' /tmp/percona-toolkit);
int=$(awk '/Host Interface/{print $4}' /tmp/percona-toolkit);
prt=$(awk '/Number of Backend Port/{print $5}' /tmp/percona-toolkit);
bbu=$(awk '/^BBU :/{print $3}' /tmp/percona-toolkit);
mem=$(awk '/Memory Size/{print $4}' /tmp/percona-toolkit);
vdr=$(awk '/Virtual Drives/{print $4}' /tmp/percona-toolkit);
dvd=$(awk '/Degraded/{print $3}' /tmp/percona-toolkit);
phy=$(awk '/^ Disks/{print $3}' /tmp/percona-toolkit);
crd=$(awk '/Critical Disks/{print $4}' /tmp/percona-toolkit);
fad=$(awk '/Failed Disks/{print $4}' /tmp/percona-toolkit);
name_val Model "${name}, ${int} interface, ${prt} ports"
name_val Cache "${mem} Memory, BBU ${bbu}"
}
# ##############################################################################
# Parse the output (saved in /tmp/pt-summary.tmp) of
# Parse the output (saved in /tmp/percona-toolkit) of
# /opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL
# ##############################################################################
parse_lsi_megaraid_bbu_status () {
charge=$(awk '/Relative State/{print $5}' /tmp/pt-summary.tmp);
temp=$(awk '/^Temperature/{print $2}' /tmp/pt-summary.tmp);
soh=$(awk '/isSOHGood:/{print $2}' /tmp/pt-summary.tmp);
charge=$(awk '/Relative State/{print $5}' /tmp/percona-toolkit);
temp=$(awk '/^Temperature/{print $2}' /tmp/percona-toolkit);
soh=$(awk '/isSOHGood:/{print $2}' /tmp/percona-toolkit);
name_val BBU "${charge}% Charged, Temperature ${temp}C, isSOHGood=${soh}"
}
# ##############################################################################
# Parse physical devices from the output (saved in /tmp/pt-summary.tmp) of
# Parse physical devices from the output (saved in /tmp/percona-toolkit) of
# /opt/MegaRAID/MegaCli/MegaCli64 -LdPdInfo -aALL
# OR, it will also work with the output of
# /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL
@@ -663,8 +663,8 @@ parse_lsi_megaraid_devices () {
echo
echo " PhysiclDev Type State Errors Vendor Model Size"
echo " ========== ==== ======= ====== ======= ============ ==========="
for dev in $(awk '/Device Id/{print $3}' /tmp/pt-summary.tmp); do
sed -e '/./{H;$!d;}' -e "x;/Device Id: ${dev}/!d;" /tmp/pt-summary.tmp \
for dev in $(awk '/Device Id/{print $3}' /tmp/percona-toolkit); do
sed -e '/./{H;$!d;}' -e "x;/Device Id: ${dev}/!d;" /tmp/percona-toolkit \
| awk '
/Media Type/ {d=substr($0, index($0, ":") + 2)}
/PD Type/ {t=$3}
@@ -682,7 +682,7 @@ parse_lsi_megaraid_devices () {
}
# ##############################################################################
# Parse virtual devices from the output (saved in /tmp/pt-summary.tmp) of
# Parse virtual devices from the output (saved in /tmp/percona-toolkit) of
# /opt/MegaRAID/MegaCli/MegaCli64 -LdPdInfo -aALL
# OR, it will also work with the output of
# /opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aAll
@@ -758,7 +758,7 @@ parse_lsi_megaraid_virtual_devices () {
devices[device ",stripe"], devices[device ",state"],
devices[device ",wpolicy"] ", " devices[device ",rpolicy"]);
}
}' /tmp/pt-summary.tmp
}' /tmp/percona-toolkit
}
# ##############################################################################
@@ -793,7 +793,7 @@ format_vmstat () {
printf format, r, b, si, so, bi, bo, ir, cs, us, sy, il, wa, st;
}
EOF
awk -f /tmp/pt-summary.awk /tmp/pt-summary.tmp
awk -f /tmp/pt-summary.awk /tmp/percona-toolkit
}
# ##############################################################################
@@ -820,7 +820,7 @@ main () {
# ########################################################################
# Grab a bunch of stuff and put it into temp files for later.
# ########################################################################
sysctl -a > /tmp/pt-summary.tmp.sysctl 2>/dev/null
sysctl -a > /tmp/percona-toolkit.sysctl 2>/dev/null
# ########################################################################
# General date, time, load, etc
@@ -926,19 +926,19 @@ main () {
# available to non-root users and usually has telltale signs. It's most
# reliable to look at /var/log/dmesg if possible. There are a number of
# other ways to find out if a system is virtualized.
cat /var/log/dmesg > /tmp/pt-summary.tmp 2>/dev/null
if [ ! -s /tmp/pt-summary.tmp ]; then
dmesg > /tmp/pt-summary.tmp 2>/dev/null
cat /var/log/dmesg > /tmp/percona-toolkit 2>/dev/null
if [ ! -s /tmp/percona-toolkit ]; then
dmesg > /tmp/percona-toolkit 2>/dev/null
fi
if [ -s /tmp/pt-summary.tmp ]; then
if [ -s /tmp/percona-toolkit ]; then
virt="$(parse_virtualization_dmesg)"
fi
if [ -z "${virt}" ]; then
if which lspci >/dev/null 2>&1; then
lspci > /tmp/pt-summary.tmp 2>/dev/null
if grep -qi virtualbox /tmp/pt-summary.tmp; then
lspci > /tmp/percona-toolkit 2>/dev/null
if grep -qi virtualbox /tmp/percona-toolkit; then
virt=VirtualBox
elif grep -qi vmware /tmp/pt-summary.tmp; then
elif grep -qi vmware /tmp/percona-toolkit; then
virt=VMWare
elif [ -e /proc/user_beancounters ]; then
virt="OpenVZ/Virtuozzo"
@@ -949,10 +949,10 @@ main () {
virt="FreeBSD Jail"
fi
elif [ "${platform}" = "SunOS" ]; then
if which prtdiag >/dev/null 2>&1 && prtdiag > /tmp/pt-summary.tmp.prtdiag 2>/dev/null; then
virt="$(parse_virtualization_generic /tmp/pt-summary.tmp.prtdiag)"
elif which smbios >/dev/null 2>&1 && smbios > /tmp/pt-summary.tmp.smbios 2>/dev/null; then
virt="$(parse_virtualization_generic /tmp/pt-summary.tmp.smbios)"
if which prtdiag >/dev/null 2>&1 && prtdiag > /tmp/percona-toolkit.prtdiag 2>/dev/null; then
virt="$(parse_virtualization_generic /tmp/percona-toolkit.prtdiag)"
elif which smbios >/dev/null 2>&1 && smbios > /tmp/percona-toolkit.smbios 2>/dev/null; then
virt="$(parse_virtualization_generic /tmp/percona-toolkit.smbios)"
fi
fi
name_val Virtualized "${virt:-No virtualization detected}"
@@ -962,23 +962,23 @@ main () {
# ########################################################################
section Processor
if [ -f /proc/cpuinfo ]; then
cat /proc/cpuinfo > /tmp/pt-summary.tmp 2>/dev/null
cat /proc/cpuinfo > /tmp/percona-toolkit 2>/dev/null
parse_proc_cpuinfo
elif [ "${platform}" = "FreeBSD" ]; then
parse_sysctl_cpu_freebsd /tmp/pt-summary.tmp.sysctl
parse_sysctl_cpu_freebsd /tmp/percona-toolkit.sysctl
elif [ "${platform}" = "SunOS" ]; then
psrinfo -v > /tmp/pt-summary.tmp
parse_psrinfo_cpus /tmp/pt-summary.tmp
psrinfo -v > /tmp/percona-toolkit
parse_psrinfo_cpus /tmp/percona-toolkit
# TODO: prtconf -v actually prints the CPU model name etc.
fi
section Memory
if [ "${platform}" = "Linux" ]; then
free -b > /tmp/pt-summary.tmp
cat /proc/meminfo >> /tmp/pt-summary.tmp
parse_free_minus_b /tmp/pt-summary.tmp
free -b > /tmp/percona-toolkit
cat /proc/meminfo >> /tmp/percona-toolkit
parse_free_minus_b /tmp/percona-toolkit
elif [ "${platform}" = "FreeBSD" ]; then
parse_memory_sysctl_freebsd /tmp/pt-summary.tmp.sysctl
parse_memory_sysctl_freebsd /tmp/percona-toolkit.sysctl
elif [ "${platform}" = "SunOS" ]; then
name_val Memory "$(prtconf | awk -F: '/Memory/{print $2}')"
fi
@@ -994,7 +994,7 @@ main () {
fi
fi
if which dmidecode >/dev/null 2>&1 && dmidecode > /tmp/pt-summary.tmp 2>/dev/null; then
if which dmidecode >/dev/null 2>&1 && dmidecode > /tmp/percona-toolkit 2>/dev/null; then
parse_dmidecode_mem_devices
fi
@@ -1010,23 +1010,23 @@ main () {
if [ "${platform}" = "Linux" ]; then
cmd="df -h -P"
fi
$cmd | sort > /tmp/pt-summary.tmp2
mount | sort | join /tmp/pt-summary.tmp2 - > /tmp/pt-summary.tmp
parse_filesystems /tmp/pt-summary.tmp "${platform}"
$cmd | sort > /tmp/percona-toolkit2
mount | sort | join /tmp/percona-toolkit2 - > /tmp/percona-toolkit
parse_filesystems /tmp/percona-toolkit "${platform}"
fi
fi
if [ "${platform}" = "Linux" ]; then
section "Disk_Schedulers_And_Queue_Size"
echo "" > /tmp/pt-summary.tmp
echo "" > /tmp/percona-toolkit
for disk in $(ls /sys/block/ | grep -v -e ram -e loop -e 'fd[0-9]'); do
if [ -e "/sys/block/${disk}/queue/scheduler" ]; then
name_val "${disk}" "$(cat /sys/block/${disk}/queue/scheduler | grep -o '\[.*\]') $(cat /sys/block/${disk}/queue/nr_requests)"
fdisk -l "/dev/${disk}" >> /tmp/pt-summary.tmp 2>/dev/null
fdisk -l "/dev/${disk}" >> /tmp/percona-toolkit 2>/dev/null
fi
done
# Relies on /tmp/pt-summary.tmp having data from the Disk Schedulers loop.
# Relies on /tmp/percona-toolkit having data from the Disk Schedulers loop.
section "Disk_Partioning"
parse_fdisk
@@ -1051,13 +1051,13 @@ main () {
# often available to non-root users. It's most reliable to look at
# /var/log/dmesg if possible.
# ########################################################################
if which lspci >/dev/null 2>&1 && lspci > /tmp/pt-summary.tmp 2>/dev/null; then
if which lspci >/dev/null 2>&1 && lspci > /tmp/percona-toolkit 2>/dev/null; then
controller="$(parse_raid_controller_lspci)"
fi
if [ -z "${controller}" ]; then
cat /var/log/dmesg > /tmp/pt-summary.tmp 2>/dev/null
if [ ! -s /tmp/pt-summary.tmp ]; then
dmesg > /tmp/pt-summary.tmp 2>/dev/null
cat /var/log/dmesg > /tmp/percona-toolkit 2>/dev/null
if [ ! -s /tmp/percona-toolkit ]; then
dmesg > /tmp/percona-toolkit 2>/dev/null
fi
controller="$(parse_raid_controller_dmesg)"
fi
@@ -1072,27 +1072,27 @@ main () {
# ########################################################################
notfound=""
if [ "${controller}" = "AACRAID" ]; then
if arcconf getconfig 1 > /tmp/pt-summary.tmp 2>/dev/null; then
if arcconf getconfig 1 > /tmp/percona-toolkit 2>/dev/null; then
parse_arcconf
elif ! which arcconf >/dev/null 2>&1; then
notfound="e.g. http://www.adaptec.com/en-US/support/raid/scsi_raid/ASR-2120S/"
fi
elif [ "${controller}" = "HP Smart Array" ]; then
if hpacucli ctrl all show config > /tmp/pt-summary.tmp 2>/dev/null; then
if hpacucli ctrl all show config > /tmp/percona-toolkit 2>/dev/null; then
parse_hpacucli
elif ! which hpacucli >/dev/null 2>&1; then
notfound="your package repository or the manufacturer's website"
fi
elif [ "${controller}" = "LSI Logic MegaRAID SAS" ]; then
if MegaCli64 -AdpAllInfo -aALL -NoLog > /tmp/pt-summary.tmp 2>/dev/null; then
if MegaCli64 -AdpAllInfo -aALL -NoLog > /tmp/percona-toolkit 2>/dev/null; then
parse_lsi_megaraid_adapter_info
elif ! which MegaCli64 >/dev/null 2>&1; then
notfound="your package repository or the manufacturer's website"
fi
if MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL -NoLog > /tmp/pt-summary.tmp 2>/dev/null; then
if MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL -NoLog > /tmp/percona-toolkit 2>/dev/null; then
parse_lsi_megaraid_bbu_status
fi
if MegaCli64 -LdPdInfo -aALL -NoLog > /tmp/pt-summary.tmp 2>/dev/null; then
if MegaCli64 -LdPdInfo -aALL -NoLog > /tmp/percona-toolkit 2>/dev/null; then
parse_lsi_megaraid_virtual_devices
parse_lsi_megaraid_devices
fi
@@ -1109,7 +1109,7 @@ main () {
# #####################################################################
if [ "${platform}" = "Linux" ]; then
section Network_Config
if which lspci > /dev/null 2>&1 && lspci > /tmp/pt-summary.tmp 2>/dev/null; then
if which lspci > /dev/null 2>&1 && lspci > /tmp/percona-toolkit 2>/dev/null; then
parse_ethernet_controller_lspci
fi
if sysctl net.ipv4.tcp_fin_timeout > /dev/null 2>&1; then
@@ -1122,14 +1122,14 @@ main () {
# /proc/sys/net/netfilter/nf_conntrack_max or /proc/sys/net/nf_conntrack_max
# in new kernels like Fedora 12?
if which ip >/dev/null 2>&1 && ip -s link > /tmp/pt-summary.tmp 2>/dev/null; then
if which ip >/dev/null 2>&1 && ip -s link > /tmp/percona-toolkit 2>/dev/null; then
section Interface_Statistics
parse_ip_s_link /tmp/pt-summary.tmp
parse_ip_s_link /tmp/percona-toolkit
fi
if [ "${platform}" = "Linux" ]; then
section Network_Connections
if netstat -antp > /tmp/pt-summary.tmp 2>/dev/null; then
if netstat -antp > /tmp/percona-toolkit 2>/dev/null; then
parse_netstat
fi
fi
@@ -1151,12 +1151,12 @@ main () {
fi
if which vmstat > /dev/null 2>&1 ; then
section "Simplified_and_fuzzy_rounded_vmstat_(wait_please)"
vmstat 1 5 > /tmp/pt-summary.tmp
vmstat 1 5 > /tmp/percona-toolkit
if [ "${platform}" = "Linux" ]; then
format_vmstat
else
# TODO: simplify/format for other platforms
cat /tmp/pt-summary.tmp
cat /tmp/percona-toolkit
fi
fi
fi

View File

@@ -3848,7 +3848,9 @@ sub get_master_status {
MKDEBUG && _d($dbh, 'SHOW MASTER STATUS');
$sth->execute();
my ($ms) = @{$sth->fetchall_arrayref({})};
MKDEBUG && _d(@$ms);
MKDEBUG && _d(
$ms ? map { "$_=" . (defined $ms->{$_} ? $ms->{$_} : '') } keys %$ms
: '');
if ( !$ms || scalar keys %$ms < 2 ) {
MKDEBUG && _d('Server on dbh', $dbh, 'does not seem to be a master');

27
t/pt-rel/pt-rel.t Normal file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 1;
use PerconaTest;
ok(
no_diff(
"cat $trunk/t/pt-rel/samples/samp01.in | $trunk/bin/pt-rel",
"t/pt-rel/samples/samp01.out",
),
"samp01"
);
# #############################################################################
# Done.
# #############################################################################
exit;

View File

@@ -0,0 +1,4 @@
Mutex spin waits 0, rounds 99584819933, OS waits 437663963
RW-shared spins 834337527, OS waits 20258150; RW-excl spins 1769749834
Mutex spin waits 0, rounds 99591465498, OS waits 437698122
RW-shared spins 834352175, OS waits 20259032; RW-excl spins 1769762980

View File

@@ -0,0 +1,4 @@
Mutex spin waits 0, rounds 99584819933, OS waits 437663963
RW-shared spins 834337527, OS waits 20258150; RW-excl spins 1769749834
Mutex spin waits 0, rounds 6645565, OS waits 34159
RW-shared spins 14648, OS waits 882; RW-excl spins 13146

24
t/pt-sift/pt-sift.t Normal file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 1;
use PerconaTest;
TODO: {
local $TODO = "Test pt-sift";
ok(1, 'ok');
};
# #############################################################################
# Done.
# #############################################################################
exit;

24
t/pt-stalk/pt-stalk.t Normal file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 1;
use PerconaTest;
TODO: {
local $TODO = "Test pt-stalk";
ok(1, 'ok');
};
# #############################################################################
# Done.
# #############################################################################
exit;

View File

@@ -1,5 +1,5 @@
#!/bin/bash
#parse_free_minus_b /tmp/aspersa
#parse_free_minus_b /tmp/percona-toolkit
cat <<EOF > $1
Total | 3.89G

View File

@@ -1,5 +1,5 @@
#!/bin/bash
#parse_ip_s_link /tmp/aspersa
#parse_ip_s_link /tmp/percona-toolkit
cat <<EOF > $1
interface rx_bytes rx_packets rx_errors tx_bytes tx_packets tx_errors

View File

@@ -1,5 +1,5 @@
#!/bin/bash
#parse_ip_s_link /tmp/aspersa
#parse_ip_s_link /tmp/percona-toolkit
cat <<EOF > $1
interface rx_bytes rx_packets rx_errors tx_bytes tx_packets tx_errors

View File

@@ -189,7 +189,7 @@ $output = output(
sleep 1;
my $row = $master_dbh->selectrow_hashref('show master status');
$output = `mysqlbinlog /tmp/12345/data/$row->{file} | grep 'use ' | sort -u`;
$output = `mysqlbinlog /tmp/12345/data/$row->{file} | grep 'use ' | grep -v '^# Warning' | sort -u`;
is(
$output,
"use mysql/*!*/;
@@ -211,7 +211,7 @@ $output = output(
sleep 1;
$row = $master_dbh->selectrow_hashref('show master status');
$output = `mysqlbinlog /tmp/12345/data/$row->{file} | grep 'use '`;
$output = `mysqlbinlog /tmp/12345/data/$row->{file} | grep 'use ' | grep -v '^# Warning'`;
is(
$output,
"use test/*!*/;

View File

@@ -32,6 +32,14 @@ else {
plan tests => 4;
}
# Previous tests slave 12347 to 12346 which makes pt-table-checksum
# complain that it cannot connect to 12347 for checking repl filters
# and such. 12347 isn't present but SHOW SLAVE HOSTS on 12346 hasn't
# figured that out yet, so we restart 12346 to refresh this list.
diag(`/tmp/12346/stop >/dev/null`);
diag(`/tmp/12346/start >/dev/null`);
$slave_dbh = $sb->get_dbh_for('slave1');
my $output;
my $cnf = "/tmp/12345/my.sandbox.cnf";
my $cmd = "$trunk/bin/pt-table-sync -F $cnf";

View File

@@ -96,7 +96,7 @@ cd $BRANCH/bin
if [ ! -f $tool ]; then
die "$tool does not exist"
fi
head -n1 $tool | grep -q bash || die "$tool is not a bash file"
head -n1 $tool | grep -q -E 'bash|sh' || die "$tool is not a bash file"
# Source the tool, i.e. import its functions.
source $tool