I want to capture the output of mpstat -P ALL 60 1 and build a maxtrix.
For example:
And I want to have output resembling:
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:
This gives me output like:
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.
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
So far I have:
Code:
mpstat -P ALL 1 10 | awk '{ for (i=1; i<=NF; i++) if ($i=="%idle") { getline; print $i }}'
Code:
# ./xx
100.00
100.00
99.22
88.46