Blame tests/p_sysstat/10-iostat-disk-basic.sh

root 2bfd68
#!/bin/bash
root 2bfd68
# Author: Steve Barnes (steve@echo.id.au)
root 2bfd68
root 2bfd68
# A simple iostat test to verify transfers are being recorded
root 2bfd68
root 2bfd68
t_Log "Running $0 - a basic iostat test to verify disk measurement"
root 2bfd68
root 2bfd68
# Save our iostat output somewhere
root 2bfd68
TMP=/tmp/iostat.disk.scratch
root 2bfd68
root 2bfd68
# dd options
root 2bfd68
BS=4196
root 2bfd68
COUNT=10100
root 2bfd68
SUM=$(expr $BS \* $COUNT / 1024)
root 2bfd68
root 2bfd68
# Clean up after ourselves
root 2bfd68
trap "[ -e $TMP ] && { /bin/rm -f $TMP; }" EXIT
root 2bfd68
root 2bfd68
# Clear out the pagecache to get an accurate reading
root 2bfd68
echo 1 > /proc/sys/vm/drop_caches
root 2bfd68
root 2bfd68
# Capture a storage device name
root 2bfd68
DRIVE=$(fdisk -l|grep -Po -m1 '^/dev/[\D]+')
root 2bfd68
root 2bfd68
# Run iostat on the device
root 2bfd68
/usr/bin/iostat -dkx 1 5 $DRIVE >$TMP &
root 2bfd68
root 2bfd68
# Let the dust settle
root 2bfd68
sleep 1
root 2bfd68
root 2bfd68
# Generate some read traffic
root 2bfd68
/bin/dd if=$DRIVE of=/dev/null bs=$BS count=$COUNT &>/dev/null
root 2bfd68
root 2bfd68
# Give iostat a chance to log our traffic
root 2bfd68
sleep 3
root 2bfd68
root 2bfd68
# Confirm our read bytes are >0, excluding the first 
root 2bfd68
# line since that's the average since boot.
root 2bfd68
BYTES_READ=$(awk '$6 ~ /[0-9]/ {NR>1 && sum+=$6} END {print int(sum)}' $TMP)
root 2bfd68
root 2bfd68
# Check we read at least as much as requested
root 2bfd68
[ "$BYTES_READ" -ge "$SUM" ] || { t_Log "iostat didn't log as much traffic as we generated?!...that ain't good"; exit $FAIL; }
root 2bfd68
root 2bfd68
t_CheckExitStatus $?