2015-03-08 12:51:15 -04:00
|
|
|
#!/bin/sh
|
2015-03-08 07:30:00 -04:00
|
|
|
|
2015-03-21 16:19:08 -04:00
|
|
|
defaults () {
|
2015-03-08 15:37:56 -04:00
|
|
|
if [ -z $DISK_IO_MOUNTPOINT ]; then
|
|
|
|
if is_osx; then
|
|
|
|
DISK_IO_MOUNTPOINT="disk0"
|
|
|
|
else
|
|
|
|
DISK_IO_MOUNTPOINT="/dev/vda"
|
|
|
|
fi
|
2015-03-08 12:51:15 -04:00
|
|
|
fi
|
2015-03-21 16:19:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
start () {
|
2015-03-28 20:04:15 -04:00
|
|
|
if ! command_exists iostat; then
|
|
|
|
echo "Warning: disk_io requires the command 'iostat' to be available"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2015-03-25 15:24:49 -04:00
|
|
|
readonly fifo=$TEMP_DIR/$(unique_id)_disk_io
|
2015-03-22 13:01:27 -04:00
|
|
|
mkfifo $fifo
|
2015-03-21 16:19:08 -04:00
|
|
|
|
|
|
|
if is_osx; then
|
2015-03-22 13:01:27 -04:00
|
|
|
bg_proc () {
|
2015-03-21 16:19:08 -04:00
|
|
|
iostat -K -d -w $INTERVAL $DISK_IO_MOUNTPOINT | while read line; do
|
2015-03-22 13:01:27 -04:00
|
|
|
echo $line | awk '{ print $3 }' > $fifo
|
2015-03-21 16:19:08 -04:00
|
|
|
done
|
|
|
|
}
|
|
|
|
else
|
2015-03-22 13:01:27 -04:00
|
|
|
bg_proc () {
|
2015-03-21 16:19:08 -04:00
|
|
|
iostat -y -m -d $INTERVAL $DISK_IO_MOUNTPOINT | while read line; do
|
2015-03-22 13:01:27 -04:00
|
|
|
echo $line | awk '/[0-9.]/{ print $3 }' > $fifo
|
2015-03-21 16:19:08 -04:00
|
|
|
done
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2015-03-22 13:01:27 -04:00
|
|
|
bg_proc &
|
2015-03-08 15:37:56 -04:00
|
|
|
}
|
2015-03-08 07:30:00 -04:00
|
|
|
|
2015-03-08 12:51:15 -04:00
|
|
|
collect () {
|
2015-03-22 13:01:27 -04:00
|
|
|
report $(cat $fifo)
|
2015-03-08 12:51:15 -04:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:19:08 -04:00
|
|
|
stop () {
|
2015-03-22 13:01:27 -04:00
|
|
|
if [ ! -z $fifo ] && [ -p $fifo ]; then
|
|
|
|
rm $fifo
|
2015-03-08 15:37:56 -04:00
|
|
|
fi
|
2015-03-08 12:51:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
docs () {
|
|
|
|
echo "Disk I/O in MB/s."
|
2015-03-21 16:19:08 -04:00
|
|
|
echo "DISK_IO_MOUNTPOINT=$DISK_IO_MOUNTPOINT"
|
2015-03-08 12:51:15 -04:00
|
|
|
}
|