Created
March 24, 2010 21:31
-
-
Save ewindisch/342848 to your computer and use it in GitHub Desktop.
Uses sar to find top io (ab)users.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#% Title: gt-topiosar | |
#% Author: Eric Windisch | |
#% License: MIT | |
# default value... | |
count=20 | |
#expr="p;" | |
filter='.' | |
set -- `getopt c:d:e: $@` >/dev/null 2>&1 | |
while [ $# -gt 0 ] | |
do | |
case "$1" in | |
-c) count=$2; shift ;; | |
-d) device=$2; shift ;; | |
-e) filter=$2; shift ;; | |
--) shift; break;; | |
-*) | |
echo >&2 \ | |
"usage: $0 [-c count] [-e expr] [-d device] [device...]" | |
exit 1;; | |
*) break;; | |
esac | |
shift | |
done | |
# push device back into $@ | |
# so we can easily just pass this along | |
# and keep it in the same array as other devs. | |
set -- $@ $device | |
#filter="sed -ne '$expr'" | |
function topn { | |
count=$1; shift; | |
echo "tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util device" | |
for line in $(sar -d | sed -n '/Average/ { s/Average:\s\+//; p; }' | sed '1,3d; s/^\(\w\+\|dev\w\+-\w\+\)\s\+\(.*\)/\2\t\1/' | sort -nr | head -n$count | sed 's/\s\+/,/g'); do | |
dmaj=$(echo $line | cut -d, -f9 | cut -d- -f1 | sed 's/^dev//;' ); | |
dmin=$(echo $line | cut -d, -f9 | cut -d- -f2); | |
dev=$(sed -n "s/^\s\+//; s/\s\+/,/g; /^${dmaj},${dmin}/p" /proc/partitions | cut -d, -f4) | |
if ( echo $dev | grep '^dm' >/dev/null 2>&1 ); then | |
dev=$(dmsetup info -c --noheadings -j $dmaj -m $dmin | cut -d: -f1); | |
fi | |
if [ -n $dev ]; then | |
echo $line | | |
sed "s/dev${dmaj}-${dmin}/${dev}/; s/,/\t\t/g;"; | |
fi | |
done | |
} | |
if [ $# -gt 0 ] && [ $count -ge $# ]; then | |
echo "IO statistics:" | |
else | |
echo "Top $count IO users:" | |
fi | |
topn $count $filter $@ | column -t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment