#! /bin/bash interval=1 if [ $# -gt 0 ]; then interval=$1 fi while (true) do iostat -k; sleep $interval; done | awk ' BEGIN{ data_flag = 0; sum_tps = 0; sum_read_kb_speed = 0; sum_write_kb_speed = 0; sum_read_kb = 0; sum_write_kb = 0; } { if ( $1 == "Device:") { data_flag = 1; #print "+ " $0 } else if ( NF == 0 ) { if (data_flag == 1) { printf("%s tps %6.2f kB_read/s %10.2f kB_write/s %10.2f kB_read %14d kB_write %14d\n", strftime("%D %H:%M:%S"), sum_tps, sum_read_kb_speed, sum_write_kb_speed, sum_read_kb, sum_write_kb); data_flag = 0; sum_tps = 0; sum_read_kb_speed = 0; sum_write_kb_speed = 0; sum_read_kb = 0; sum_write_kb = 0; #print "- " $0 } else { #print "= " $0 } #data_flag=0; } else { if (data_flag == 1) { #print "1 " $0; tps = $2; read_kb_speed = $3; write_kb_speed = $4; read_kb = $5; write_kb = $6; sum_tps += tps; sum_read_kb_speed += read_kb_speed; sum_write_kb_speed += write_kb_speed; sum_read_kb += read_kb; sum_write_kb += write_kb; } else { #print "0 " $0; } } } END{ }
運行後效果如下: 是不是顯示好多了。且有時間顯示,這樣定入log後定位問題方便很多