INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Build matrix from mpstat data

Build matrix from mpstat data

(OP)
I want to capture the output of mpstat -P ALL 60 1 and build a maxtrix.

For example:

CODE

# mpstat -P ALL 1 2
Linux 2.6.18-308.8.2.el5 (myserver)     11/16/2012

01:24:28 PM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
01:24:29 PM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00   1034.02
01:24:29 PM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00   1031.96
01:24:29 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00
01:24:29 PM    2    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      1.03
01:24:29 PM    3    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00

01:24:29 PM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
01:24:30 PM  all    0.00    0.00    0.00    0.26    0.00    0.00    0.00   99.74   1058.76
01:24:30 PM    0    0.00    0.00    0.00    1.03    0.00    0.00    0.00   98.97   1054.64
01:24:30 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00
01:24:30 PM    2    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      4.12
01:24:30 PM    3    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00

Average:     CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
Average:     all    0.00    0.00    0.00    0.13    0.00    0.00    0.00   99.87   1046.39
Average:       0    0.00    0.00    0.00    0.52    0.00    0.00    0.00   99.48   1043.30
Average:       1    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00
Average:       2    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      2.58
Average:       3    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00 

And I want to have output resembling:

CODE

0, 98, 97, 95, 72, 73, 100
1, 88, 100, 96, 8, 99, 99
2, 87, 100, 100, 10, 22, 11
3, 99, 99, 99, 99, 98, 98
,01:24:30, 01:24:31, 01:24:32, 01:24:33, 01:24:34, 01:24:35 
Where the time on the last row is the time from mpstat so the interval could change, and the number of idle columns would be equal to the count from mpstat.

So far I have:

CODE

mpstat -P ALL 1 10 | awk '{ for (i=1; i<=NF; i++) if ($i=="%idle") { getline; print $i }}' 
This gives me output like:

CODE

# ./xx
100.00
100.00
99.22
88.46 
But am not certain how to get the cpu number and add the time plus add columns for each interval and put into a text file.

RE: Build matrix from mpstat data

(OP)
Input would be from `mpstat -P ALL 1 2`

CODE

Linux 2.6.18-308.8.2.el5 (myserver)     11/16/2012

01:24:28 PM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
01:24:29 PM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00   1034.02
01:24:29 PM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00   1031.96
01:24:29 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00
01:24:29 PM    2    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      1.03
01:24:29 PM    3    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00

01:24:29 PM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
01:24:30 PM  all    0.00    0.00    0.00    0.26    0.00    0.00    0.00   99.74   1058.76
01:24:30 PM    0    0.00    0.00    0.00    1.03    0.00    0.00    0.00   98.97   1054.64
01:24:30 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00
01:24:30 PM    2    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      4.12
01:24:30 PM    3    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00

Average:     CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
Average:     all    0.00    0.00    0.00    0.13    0.00    0.00    0.00   99.87   1046.39
Average:       0    0.00    0.00    0.00    0.52    0.00    0.00    0.00   99.48   1043.30
Average:       1    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00
Average:       2    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      2.58
Average:       3    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00      0.00 

Output:

CODE

0, 100.00, 99.74
1, 100.00, 98.97
2, 100.00, 100.00
3, 100.00, 100.00
,01:24:29, 01:24:30 

But if mpstat was ran with a count of say 20 (mpstat -P ALL 1 20) then there would be 20 columns.

RE: Build matrix from mpstat data

Sorry, I'm not a mind reader.
Why did you not explain CLEALY (ie in good english words) what you want ?

RE: Build matrix from mpstat data

(OP)
The first column is the cpu number and column1, column2, columnN for each cpu is from %idle. The last row is the time from each interval of mpstat but since a cpu doesn't have a "time" it is empty and thus, just a comman is written.

RE: Build matrix from mpstat data

Your expected output makes no sense for me as for CPU 0 you put the stats of CPU all ...

RE: Build matrix from mpstat data

(OP)
Whatever, Dude. I'll figure it out myself since it is above your head. Not sure how you disable a login or remove yourself, but I won't be returning. Waste of my time.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close