metrics.sh/metrics/disk_io.sh

41 lines
771 B
Bash
Raw Normal View History

2015-03-08 12:51:15 -04:00
#!/bin/sh
init () {
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
readonly __disk_io_fifo=$__TEMP_DIR/disk_io
mkfifo $__disk_io_fifo
__disk_io_bgproc &
}
2015-03-08 12:51:15 -04:00
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 () {
echo $(iostat -y -d 1 $DISK_IO_MOUNTPOINT)
}
fi
2015-03-08 12:51:15 -04:00
collect () {
report $(cat $__disk_io_fifo)
}
terminate () {
if [ ! -z $__disk_io_fifo ] && [ -f $__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"
}