metrics.sh/metrics/disk_io.sh

52 lines
941 B
Bash
Raw Permalink 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 () {
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
if is_osx; then
2015-03-22 13:01:27 -04:00
bg_proc () {
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
done
}
else
2015-03-22 13:01:27 -04:00
bg_proc () {
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
done
}
fi
2015-03-22 13:01:27 -04:00
bg_proc &
}
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
}
stop () {
2015-03-22 13:01:27 -04:00
if [ ! -z $fifo ] && [ -p $fifo ]; then
rm $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
}