public
Created

Disk stats script

  • Download Gist
disk_stats.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#!/bin/bash
 
DISKS=('sda' 'sda2')
OUT_DIR=/srv/http/
RRD_DIR=/srv/shared/
 
NOW=$(date +%s)
 
for disk_name in ${DISKS[@]}; do
 
RRDFILE=${RRD_DIR}disk.${disk_name}.rrd
 
case $1 in
create)
rrdtool create $RRDFILE \
--start ${NOW} \
DS:reads:COUNTER:60:U:U \
DS:writes:COUNTER:60:U:U \
DS:write_ms:COUNTER:60:U:U \
DS:io_ms:COUNTER:60:U:U \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775
 
;;
update)
reads=$(/srv/bin/dsutil reads_issued ${disk_name})
writes=$(/srv/bin/dsutil writes_completed ${disk_name})
time_read=$(/srv/bin/dsutil spent_read ${disk_name})
io_time=$(/srv/bin/dsutil time_io ${disk_name})
/usr/bin/rrdtool update $RRDFILE \
N:$reads:$writes:$time_read:$io_time
 
;;
graph)
/usr/bin/rrdtool graph ${OUT_DIR}diskio_${disk_name}.png \
--title "IO calls on ${disk_name}" \
DEF:read=$RRDFILE:reads:AVERAGE \
DEF:write=$RRDFILE:writes:AVERAGE \
LINE3:read#FF0000:"Reads" \
LINE3:write#22FF00:"Writes" \
-s -1h -v "IO Calls"
/usr/bin/rrdtool graph ${OUT_DIR}diskio_6hr_${disk_name}.png \
--title "IO calls on ${disk_name} (6hr)" \
DEF:read=$RRDFILE:reads:AVERAGE \
DEF:write=$RRDFILE:writes:AVERAGE \
LINE3:read#FF0000:"Read" \
LINE3:write#22FF00:"Writes" \
-s -6h -v "IO calls"
/usr/bin/rrdtool graph ${OUT_DIR}disktime_${disk_name}.png \
--title "IO Time on ${disk_name}" \
DEF:total=$RRDFILE:io_ms:AVERAGE \
DEF:write=$RRDFILE:write_ms:AVERAGE \
AREA:total#11ad00:"Total time" \
LINE2:write#4411ff:"Write Time" \
-s -1h -v "I/O Time (ms)"
/usr/bin/rrdtool graph ${OUT_DIR}disktime_6hr_${disk_name}.png \
--title "IO TIme on ${disk_name} (6hr)" \
DEF:total=$RRDFILE:io_ms:AVERAGE \
DEF:write=$RRDFILE:write_ms:AVERAGE \
AREA:total#11ad00:"Total Time" \
LINE2:write#4411ff:"Write Time" \
-s -6h -v "I/O Time (ms)"
;;
*)
echo "wut";
exit 1;
;;
esac
 
done
dsutil
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/bin/bash
 
if [ "x$1" == "x" ]; then
echo "no argument given."
exit 1
fi
if [ "$x2" == "x" ]; then
echo "no disk/partition given"
exit 1
fi
 
DISK=$2
 
disk_info=$( cat /proc/diskstats | grep "$DISK " | sed -e 's/ */ /g' | cut -f 5 - -d " ")
 
function getfield()
{
echo $disk_info | cut -f $1 -d " "
}
 
case $1 in
reads_issued) getfield 1 ;;
reads_merged) getfield 2 ;;
sectors_read) getfield 3 ;;
spent_read) getfield 4 ;;
writes_completed) getfield 5 ;;
writes_merged) getfield 6 ;;
sectors_written) getfield 7 ;;
spent_writing) getfield 8 ;;
in_progress) getfield 10;;
time_io) getfield 11;;
*) echo "Unkown argument $1. Need one of:"
echo "{reads_issued|reads|merged|sectors_read|spent_read|writes_compl eted|writes_merged"
echo "|sectors_written|spent_writing|in_progress|time_io}"
exit 1
;;
esac

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.