你的位置:首页 > 操作系统

[操作系统]Shell脚步之监控iostat数据


在性能测试中,进行iostat监控数据显示太不美观,看起来很痛苦,如下图

为了显示美观,写个shell脚本进行改造,如下:

#! /bin/bashinterval=1if [ $# -gt 0 ]; then interval=$1fiwhile (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后定位问题方便很多

 

iostat参考见:http://www.ha97.com/4546.html