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"
BASEDIR="$PWD"
if [ -d "/var/lib/pt-stalk" ]; then
BASEDIR="/var/lib/pt-stalk"
else
BASEDIR="$PWD"
fi
PREFIX=""
# ###########################################################################
@@ -150,7 +154,7 @@ main() {
# there is no PREFIX yet. NOTE: we rely on the "-df" files here.
(
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
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
DEFAULT)
echo "--diskstats--"
if [ -f "${BASEDIR}/${PREFIX}-diskstats" ]; then
$PR_diskstats --group-by disk "${BASEDIR}/${PREFIX}-diskstats" \
| awk '
/ts/ { header = $0 }
/[0-9]/ {
io = $3 + $9;
if ( io >= mio ) {
mio = io;
mseen = $0;
$PR_diskstats --group-by disk "${BASEDIR}/${PREFIX}-diskstats" \
| awk '
/ts/ { header = $0 }
/[0-9]/ {
io = $3 + $9;
if ( io >= mio ) {
mio = io;
mseen = $0;
}
}
}
END {
print header;
print mseen;
}'
END {
print header;
print mseen;
}'
# Find out which device was the busiest.
mdev="$($PR_diskstats --group-by disk "${BASEDIR}/${PREFIX}-diskstats" \
| awk '
/[0-9]/ {
io = $3 + $9;
if ( io >= mio ) {
mio = io;
mdev = $2;
# Find out which device was the busiest.
mdev="$($PR_diskstats --group-by disk "${BASEDIR}/${PREFIX}-diskstats" \
| awk '
/[0-9]/ {
io = $3 + $9;
if ( io >= mio ) {
mio = io;
mdev = $2;
}
}
}
END {
print mdev;
}')"
END {
print mdev;
}')"
# Print the busy% for that device, rounded to the nearest N%, with
# "." as a marker for a repeated value.
$PR_diskstats --group-by sample "${BASEDIR}/${PREFIX}-diskstats" \
| awk "
# Print the busy% for that device, rounded to the nearest N%, with
# "." as a marker for a repeated value.
$PR_diskstats --group-by sample "${BASEDIR}/${PREFIX}-diskstats" \
| 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 {
fuzz = 5;
printf \" ${mdev} \"
printf \"wa\"
}
\$1 = \"${mdev}\" {
busy_rounded = fuzz * sprintf(\"%d\", substr(\$15, 1, length(\$15) - 1) / fuzz);
if ( printed == 1 && prev == busy_rounded ) {
/[0-9]/ {
wa_rounded = fuzz * sprintf(\"%d\", \$${wa_col} / fuzz);
if ( printed == 1 && prev == wa_rounded ) {
printf \" .\";
}
else {
printf \" %d%%\", busy_rounded;
prev = busy_rounded;
printf \" %d%%\", wa_rounded;
prev = wa_rounded;
printed = 1;
}
}"
echo
echo "--vmstat--"
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 {
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
}" "${BASEDIR}/${PREFIX}-vmstat"
echo
else
echo " No vmstat file exists"
fi
echo "--innodb--"
awk '
@@ -594,13 +606,12 @@ pt-sift - Browses files created by pt-stalk.
Usage: pt-sift FILE|PREFIX|DIRECTORY
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.
Specify a DIRECTORY to browse all files in that directory. Specify
a FILE to browse all files with the same prefix in that file's directory.
Specify a PREFIX to browse all files in the current working directory
with that prefix. Prefixes are timestamps like C<2012_07_23_14_27_11>.
The tool prompts for a prefix if more than is found, else the only available
prefix is used by default.
the tool browses all pt-stalk files in C</var/lib/pt-stalk> if that directory
exists, else the current working directory is used. If a FILE is given,
the tool browses files with the same prefix in the given file's directory.
If a PREFIX is given, the tool browses files in C</var/lib/pt-stalk>
(or the current working directory) with the same prefix. If a DIRECTORY
is given, the tool browses all pt-stalk files in it.
=head1 RISKS