Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Build matrix from mpstat data 1

Status
Not open for further replies.

Longmire

Technical User
Nov 16, 2012
4
US
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.
 
Please, explain CLEARLY what are the values you want in the output depending of what is the input.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
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.
 
Sorry, I'm not a mind reader.
Why did you not explain CLEALY (ie in good english words) what you want ?
 
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.
 
Your expected output makes no sense for me as for CPU 0 you put the stats of CPU all ...
 
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.
 
Anyway, a starting point:
mpstat your options here | awk '
$1=="Average:"{exit}
$3=="CPU"{t=t","$1;next}
/^..:/{e=$1;i[$3]=i[$3]","$11}
END{for(a in i)print a,i[a]|"sort";print t}
'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top