Created
January 26, 2013 05:53
-
-
Save indrora/4640454 to your computer and use it in GitHub Desktop.
Disk stats script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment