Suppress ls output when it fails. Handle missing diskstats and vmstat. Shorten synopsis.

This commit is contained in:
Daniel Nichter
2012-07-23 16:39:49 -06:00
parent 8742381029
commit 4f0661c102

View File

@@ -59,7 +59,11 @@ rm_tmpdir() {
# ########################################################################### # ###########################################################################
TOOL="pt-sift" TOOL="pt-sift"
BASEDIR="$PWD" if [ -d "/var/lib/pt-stalk" ]; then
BASEDIR="/var/lib/pt-stalk"
else
BASEDIR="$PWD"
fi
PREFIX="" PREFIX=""
# ########################################################################### # ###########################################################################
@@ -150,7 +154,7 @@ main() {
# there is no PREFIX yet. NOTE: we rely on the "-df" files here. # there is no PREFIX yet. NOTE: we rely on the "-df" files here.
( (
cd "$BASEDIR" cd "$BASEDIR"
ls *-df | cut -d- -f1 | sort > "$PT_TMPDIR/pt-sift.prefixes" ls *-df 2>/dev/null | cut -d- -f1 | sort > "$PT_TMPDIR/pt-sift.prefixes"
) )
if [ ! -s "$PT_TMPDIR/pt-sift.prefixes" ]; then if [ ! -s "$PT_TMPDIR/pt-sift.prefixes" ]; then
echo "Error: There are no pt-stalk files in $BASEDIR" >&2 echo "Error: There are no pt-stalk files in $BASEDIR" >&2
@@ -206,80 +210,88 @@ main() {
# Format a brief report: busiest device's disk stats, CPU stats # Format a brief report: busiest device's disk stats, CPU stats
DEFAULT) DEFAULT)
echo "--diskstats--" echo "--diskstats--"
if [ -f "${BASEDIR}/${PREFIX}-diskstats" ]; then
$PR_diskstats --group-by disk "${BASEDIR}/${PREFIX}-diskstats" \ $PR_diskstats --group-by disk "${BASEDIR}/${PREFIX}-diskstats" \
| awk ' | awk '
/ts/ { header = $0 } /ts/ { header = $0 }
/[0-9]/ { /[0-9]/ {
io = $3 + $9; io = $3 + $9;
if ( io >= mio ) { if ( io >= mio ) {
mio = io; mio = io;
mseen = $0; mseen = $0;
}
} }
} END {
END { print header;
print header; print mseen;
print mseen; }'
}'
# Find out which device was the busiest. # Find out which device was the busiest.
mdev="$($PR_diskstats --group-by disk "${BASEDIR}/${PREFIX}-diskstats" \ mdev="$($PR_diskstats --group-by disk "${BASEDIR}/${PREFIX}-diskstats" \
| awk ' | awk '
/[0-9]/ { /[0-9]/ {
io = $3 + $9; io = $3 + $9;
if ( io >= mio ) { if ( io >= mio ) {
mio = io; mio = io;
mdev = $2; mdev = $2;
}
} }
} END {
END { print mdev;
print mdev; }')"
}')"
# Print the busy% for that device, rounded to the nearest N%, with # Print the busy% for that device, rounded to the nearest N%, with
# "." as a marker for a repeated value. # "." as a marker for a repeated value.
$PR_diskstats --group-by sample "${BASEDIR}/${PREFIX}-diskstats" \ $PR_diskstats --group-by sample "${BASEDIR}/${PREFIX}-diskstats" \
| awk " | awk "
BEGIN {
fuzz = 5;
printf \" ${mdev} \"
}
\$1 = \"${mdev}\" {
busy_rounded = fuzz * sprintf(\"%d\", substr(\$15, 1, length(\$15) - 1) / fuzz);
if ( printed == 1 && prev == busy_rounded ) {
printf \" .\";
}
else {
printf \" %d%%\", busy_rounded;
prev = busy_rounded;
printed = 1;
}
}"
echo
else
echo " No diskstats file exists"
fi
echo "--vmstat--"
if [ -f "${BASEDIR}/${PREFIX}-vmstat" ]; then
tail -n 3 "${BASEDIR}/${PREFIX}-vmstat-overall" | $PR_align
# Figure out which column is 'wa' and print this, similar to the
# busy% for disks above.
wa_col="$(awk '/swpd/{for(i=1;i<=NF;++i){if($i=="wa"){print i; exit}}}' "${BASEDIR}/${PREFIX}-vmstat")"
awk "
BEGIN { BEGIN {
fuzz = 5; fuzz = 5;
printf \" ${mdev} \" printf \"wa\"
} }
\$1 = \"${mdev}\" { /[0-9]/ {
busy_rounded = fuzz * sprintf(\"%d\", substr(\$15, 1, length(\$15) - 1) / fuzz); wa_rounded = fuzz * sprintf(\"%d\", \$${wa_col} / fuzz);
if ( printed == 1 && prev == busy_rounded ) { if ( printed == 1 && prev == wa_rounded ) {
printf \" .\"; printf \" .\";
} }
else { else {
printf \" %d%%\", busy_rounded; printf \" %d%%\", wa_rounded;
prev = busy_rounded; prev = wa_rounded;
printed = 1; printed = 1;
} }
}" }" "${BASEDIR}/${PREFIX}-vmstat"
echo echo
else
echo "--vmstat--" echo " No vmstat file exists"
tail -n 3 "${BASEDIR}/${PREFIX}-vmstat-overall" | $PR_align fi
# Figure out which column is 'wa' and print this, similar to the
# busy% for disks above.
wa_col="$(awk '/swpd/{for(i=1;i<=NF;++i){if($i=="wa"){print i; exit}}}' "${BASEDIR}/${PREFIX}-vmstat")"
awk "
BEGIN {
fuzz = 5;
printf \"wa\"
}
/[0-9]/ {
wa_rounded = fuzz * sprintf(\"%d\", \$${wa_col} / fuzz);
if ( printed == 1 && prev == wa_rounded ) {
printf \" .\";
}
else {
printf \" %d%%\", wa_rounded;
prev = wa_rounded;
printed = 1;
}
}" "${BASEDIR}/${PREFIX}-vmstat"
echo
echo "--innodb--" echo "--innodb--"
awk ' awk '
@@ -594,13 +606,12 @@ pt-sift - Browses files created by pt-stalk.
Usage: pt-sift FILE|PREFIX|DIRECTORY Usage: pt-sift FILE|PREFIX|DIRECTORY
pt-sift browses files created by L<pt-stalk>. If no options are given, pt-sift browses files created by L<pt-stalk>. If no options are given,
the tool browses all pt-stalk files in the current working directory. the tool browses all pt-stalk files in C</var/lib/pt-stalk> if that directory
Specify a DIRECTORY to browse all files in that directory. Specify exists, else the current working directory is used. If a FILE is given,
a FILE to browse all files with the same prefix in that file's directory. the tool browses files with the same prefix in the given file's directory.
Specify a PREFIX to browse all files in the current working directory If a PREFIX is given, the tool browses files in C</var/lib/pt-stalk>
with that prefix. Prefixes are timestamps like C<2012_07_23_14_27_11>. (or the current working directory) with the same prefix. If a DIRECTORY
The tool prompts for a prefix if more than is found, else the only available is given, the tool browses all pt-stalk files in it.
prefix is used by default.
=head1 RISKS =head1 RISKS