Monitoring iostat data using Shell

Source: Internet
Author: User

Monitoring iostat data using Shell
In performance testing, iostat monitoring data is too bad to display and looks very painful. For example, to display the appearance, write a shell script for transformation, as shown below:

#! /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{}

 

The effect after running is as follows: is it better. There is time to display, so it is much easier to locate the problem after logging.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.