metrics.sh/metrics/disk_io.sh

47 lines
912 B
Bash
Raw Normal View History

2015-03-08 12:51:15 -04:00
#!/bin/sh
defaults () {
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
}
start () {
readonly __disk_io_fifo=$TEMP_DIR/$(unique_id)
mkfifo $__disk_io_fifo
if is_osx; then
__disk_io_bgproc () {
iostat -K -d -w $INTERVAL $DISK_IO_MOUNTPOINT | while read line; do
echo $line | awk '{ print $3 }' > $__disk_io_fifo
done
}
else
__disk_io_bgproc () {
iostat -y -m -d $INTERVAL $DISK_IO_MOUNTPOINT | while read line; do
echo $line | awk '/[0-9.]/{ print $3 }' > $__disk_io_fifo
done
}
fi
__disk_io_bgproc &
}
2015-03-08 12:51:15 -04:00
collect () {
report $(cat $__disk_io_fifo)
2015-03-08 12:51:15 -04:00
}
stop () {
if [ ! -z $__disk_io_fifo ] && [ -p $__disk_io_fifo ]; then
rm $__disk_io_fifo
fi
2015-03-08 12:51:15 -04:00
}
docs () {
echo "Disk I/O in MB/s."
echo "DISK_IO_MOUNTPOINT=$DISK_IO_MOUNTPOINT"
2015-03-08 12:51:15 -04:00
}