Parsing iostat data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing iostat data
# 1  
Old 03-22-2012
Parsing iostat data

Hello,

I searched the forum and found the parsing iostat data in real time but that does not help me. What I would like to do is to parse the iostat data that has been gathered. Below is an example of the iostat output:

Code:
System configuration: lcpu=4 drives=5 ent=0.10 paths=20 vdisks=2

tty:      tin         tout    avg-cpu: % user % sys % idle % iowait physc % entc
          0.0          0.0                7.3  69.6   21.0      2.2   1.0  988.6

Disks:        % tm_act     Kbps      tps    Kb_read   Kb_wrtn
hdisk7           0.0       0.0       0.0          0         0
hdisk9           1.0      40.0       9.0          0        40
hdisk6           0.0       0.0       0.0          0         0
hdisk8           0.0       0.0       0.0          0         0
hdisk5           0.0       0.0       0.0          0         0

tty:      tin         tout    avg-cpu: % user % sys % idle % iowait physc % entc
          0.0          0.0                7.7  69.1   20.9      2.2   1.0  993.1

Disks:        % tm_act     Kbps      tps    Kb_read   Kb_wrtn
hdisk7           0.0       0.0       0.0          0         0
hdisk9           0.0      40.0       9.0          0        40
hdisk6           0.0       0.0       0.0          0         0
hdisk8           0.0       0.0       0.0          0         0
hdisk5           0.0       0.0       0.0          0         0

As you can see, there are 2 intervals of the iostat output. What I would like to do is to use awk or sed to sum the tps column, Kb_read column, and Kb_wrtn column for all disks within each interval. The result would be something like:

Code:
Interval 1= total tps, Kb_read, Kb_write for disks hdisk5 to hdisk9
Interval 2= total tps, Kb_read, Kb_write for disks hdisk5 to hdisk9

Thanks for your help.


Tom

Last edited by methyl; 03-23-2012 at 03:10 PM.. Reason: please use code tags
# 2  
Old 03-22-2012
Try this:

Code:
awk '
   /^Disks:/{++i}
   /^hdisk/{tps[i]+=$(NF-2);kbr[i]+=$(NF-1);kbw[i]+=$(NF)};
   END{
       for(j=1;j<=i;j++)
           print "Interval "j"=" tps[j], kbr[j], kbw[j]}' OFS=, infile

# 3  
Old 03-23-2012
Thank you, Chubler. That works great. One more question, how can I pass the infile as a parameter to the script?

Thanks again.

Tom
# 4  
Old 03-23-2012
Two options keep the output of iostat in a file and pass to script.

Code:
# iostat ...... > /tmp/myinfile

In this case replace infile at the end of the script with /tmp/infile.

or pipe output of command diretly to the script

Code:
# iostate ..... | /usr/local/bin/parseiostat.sh

In this case I assume you have saved the script I supplied as /usr/local/bin/parseiostat.sh you would then remove the infile from the end of the command to have awk process the stdin.
# 5  
Old 03-23-2012
Thank you, Chubler. You've been a tremendous help. I have never used awk in this complex form. What I am trying to do is to make it a little better. I would like to also come up with percentage read and percentage write by using KB_read / (KB_read + KB_write). Can you help me with this? Add the math logic to your script?

thanks,

Tom
# 6  
Old 03-23-2012
Maths is awk is pretty straight forward and looks much like you would expect.

Code:
awk '
    /^Disks:/{++i}
    /^hdisk/{tps[i]+=$(NF-2);kbr[i]+=$(NF-1);kbw[i]+=$(NF)};
    END{
        for(j=1;j<=i;j++)
            print "Interval "j"=" tps[j], kbr[j], kbw[j],
               100 * kbr[j] / ( kbr[j] + kbw[j]),
               100 * kbw[j] / ( kbr[j] + kbw[j]) }' OFS=, infile

Formatting output (eg reducing number of decimal places, leading zeros, etc) may require printf
# 7  
Old 03-23-2012
MySQL

Chubler,

All I can say is "You are Da Man!". You have saved me a ton of time. I really appreciate your help.

thanks much,

Tom
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing XML (and insert data) then output data (bash / Solaris)

Hi folks I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file. It all works - apart from the xml and config file format in the new file with XML files the original XML (that ends up in... (2 Replies)
Discussion started by: dfinch
2 Replies

2. Shell Programming and Scripting

Parsing file data

Hey Guys, I'm a novice at shell scripts and i need some help parsing file data. Basically, I want to write a script that retrieves URLs. Here is what I have so far. #!/bin/bash echo "Please enter start date (format: yyyy-mm-dd):\c" read STARTDATE echo "Please enter end date... (7 Replies)
Discussion started by: silverdust
7 Replies

3. Shell Programming and Scripting

Help with parsing data with awk , eliminating unwanted data

Experts , Below is the data: --- Physical volumes --- PV Name /dev/dsk/c1t2d0 VG Name /dev/vg00 PV Status available Allocatable yes VGDA 2 Cur LV 8 PE Size (Mbytes) 8 Total PE 4350 Free PE 2036 Allocated PE 2314 Stale PE 0 IO Timeout (Seconds) default --- Physical volumes ---... (5 Replies)
Discussion started by: rveri
5 Replies

4. Shell Programming and Scripting

Data parsing

Hi, I do have a data file which is divided into compartments by ---------. I would like to extract (parse) some of the data and numbers either using awk or sed The file has the format: CATGC Best GO enrichment: Genes/ORF that have the motifs (genes are sorted by max(pa+pd+po)): ... (6 Replies)
Discussion started by: Lucky Ali
6 Replies

5. Shell Programming and Scripting

Help in Parsing data

I have below string Transaction_ID:SDP-DM-151204679 , Transaction_DateTime:2011-02-11 00:00:15 GMT+05:30 , Transaction_Mode:WAP , Circle_ID:4 , Circle_Name:BJ ,Zone: , CustomerID:B_31563486 , MSISDN:7870904329 , IMSI:405876122068099 , IMEI: , Sub_Profile:Pre-Paid , CPID:Nazara , CPNAME:Nazara ,... (6 Replies)
Discussion started by: poweroflinux
6 Replies

6. Shell Programming and Scripting

Parsing the data

Hi friends, I need to parse the following data in the given format and get the desired output. I need a function, which takes the input as a parameter and the desired output will be returned from the function. INPUT(single parameter as complete string) A;BCF;DFG;FD ... (3 Replies)
Discussion started by: sumesh.1988
3 Replies

7. Shell Programming and Scripting

Parsing iostat in real time

I'm trying to write a script that will parse the output of the iostat command in real time and place the output in csv file(s). I do have a programming background, but am relatively new to shell so I'm having difficulties determining how to proceed. The cpu stats will go into one output... (6 Replies)
Discussion started by: fastergrace
6 Replies

8. Shell Programming and Scripting

Parsing data

Hi all , I have a file with billing CDR records in it. I need to parse that information (row format) . The purpose is to compare full content. The example I have given below is a single line record but it has two portions, (1) the line start with “!” and end with “1.2.1.8” and (2) second part... (5 Replies)
Discussion started by: jaygamini
5 Replies

9. Shell Programming and Scripting

parsing data for certain conditions

Hi guys, I have got this working OK but I am sure there is a more efficient/elegant way of doing it, which I hope you can help me with. It can be done in whatever is most suitable i.e perl/awk.. Any suggestions are welcome and many thanks in advance. What I require is to extract... (5 Replies)
Discussion started by: PAW
5 Replies

10. Shell Programming and Scripting

Parsing the data

Hi I need to parse the following data using shell script Table ----- stage4n_abc 48 stage4o_abcd 4 adashpg_abc_HeartBeat 1 stage4l_asc 168 Can anyone gimme the solution. I want each value to get stored in an array or variable and want the value to be greped from another file.... (1 Reply)
Discussion started by: Archana.Dheepan
1 Replies
Login or Register to Ask a Question