Mpstat script output


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mpstat script output
# 1  
Mpstat script output

I have a script which runs the mpstat and prints the output in a file. In order capture highest cpu ususage from the generated output file,
have to manually tail the output file and need to grab which cpu has highest value (which is very annoying)

Is there a way we can automate that process of getting highest cpu usuage.

main script :
Code:
root@UTC # less mympstat.ksh
#!/bin/ksh
PATH=/usr/bin:/usr/sbin:$PATH
export PATH
if [ "$1" != "" ] ;then
  [ $1 -gt 0 ] && TIME=$1
else
  TIME=1
fi
LOG_BASE=${LOG_BASE:-/rit/logs/}
HOST=`hostname`
[ -d $LOG_BASE/cap ] || mkdir -p $LOG_BASE/cap
if [ ! -f $LOG_BASE/cap/mpstat_${HOST}_`date '+%Y%m%d'`.csv ];then
  echo "Date Time,CPU ID,User,System,Wait,CPU_Use" \
> $LOG_BASE/cap/mpstat_${HOST}_`date '+%Y%m%d'`.csv
fi
mpstat $TIME | while read r
do
  echo "`date '+%Y/%m/%d %H:%M:%S'` $r" |nawk '$3 !~ /CPU/ \
{printf \
  "%s %s,%d,%d,%d,%d,%d\n", \
  $1,$2,$3,$15,$16,$17,100-$18 \
}' >> $LOG_BASE/cap/mpstat_${HOST}_`date '+%Y%m%d'`.csv
done

when we tail the output file we get :
Code:
root@UTC # tail  -f /rit/logs/cap/mpstat_UTC_20130823.csv
2013/08/23 09:21:14,0,2,2,0,4
2013/08/23 09:21:14,1,0,0,0,0
2013/08/23 09:21:14,2,1,2,0,3
2013/08/23 09:21:14,3,0,1,0,1
2013/08/23 09:21:14,4,0,1,0,1
2013/08/23 09:21:14,5,1,1,0,2
2013/08/23 09:21:14,6,0,0,0,0
2013/08/23 09:21:14,7,0,1,0,1

2013/08/23 09:21:15,0,2,2,0,3
2013/08/23 09:21:15,1,0,0,0,2
2013/08/23 09:21:15,2,1,2,0,1
2013/08/23 09:21:15,3,0,1,0,6
2013/08/23 09:21:15,4,0,1,0,11
2013/08/23 09:21:15,5,1,1,0,23
2013/08/23 09:21:15,6,0,0,0,0
2013/08/23 09:21:15,7,0,1,0,11

from the above output, i need to manually look for highest cpu usuage ie (last column value) from the second set say 23 and note down its cpu ie, 5

I need to capture this values after every 10 secs from the output file (tail command)

expected output : read the mpstat_UTC_20130823.csv from a another script and calculate the highest cpu usuage and number for every 10 sec and then
just display that line saying

Code:
highest cpu usuage is : 2013/08/23 09:21:14,0,2,2,0,4
highest cpu usuage is : 2013/08/23 09:21:14,5,1,1,0,23

# 2  
Does this help?

Code:
awk -F"," '{if($NF>a[$1]) {a[$1]=$NF}} END{for(i in a) {print "highest cpu usage is : "i,a[i]}}' /rit/logs/cap/mpstat_UTC_20130823.csv

# 3  
Thanks krishmaths for quick response.

your awk command prints only last column value but i need to have cpu number(column value next to date field) + last column value in the output

Can you please show how to print that column as well.

---------- Post updated at 06:07 AM ---------- Previous update was at 06:06 AM ----------

Thanks krishmaths for quick response.

your awk command prints only last column value but i need to have cpu number(column value next to date field) + last column value in the output

Can you please show how to print that column as well.
# 4  
To print the entire line:
Code:
awk -F"," '{if($NF>a[$1]) {a[$1]=$NF;b[$1]=$0}} END{for(i in a) {print "highest cpu usage is : "b[i]}}'  /rit/logs/cap/mpstat_UTC_20130823.csv

To print only the second column:
Code:
awk -F"," '{if($NF>a[$1]) {a[$1]=$NF;b[$1]=$2}} END{for(i in a) {print "highest cpu usage is : "i,b[i]}}'  /rit/logs/cap/mpstat_UTC_20130823.csv

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #902
Difficulty: Medium
According to Top500, as of 2019 100% of the worlds 500 fastest supercomputers run Linux.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to get average idle time using mpstat

I want to get average idle time of the server using mpstat. The problem I am having is %idle is not in same columns in all the versions of linux. example 1: example 2: I tried below command as generalized solution but as Average as one less column output is not proper. I am... (1 Reply)
Discussion started by: kumarjohn
1 Replies

2. UNIX and Linux Applications

Graphical Representation of mpstat.out file

hi everyone, We've generated mpstat.out file monitoring cpu utilization and the file is ready now.Wanted to generate graphical charts for the same output data. Can anyone pleas suggest tool for the same.? (1 Reply)
Discussion started by: Kathraji
1 Replies

3. Shell Programming and Scripting

One script for Linux Monitoring-free, sar, vmstat, mpstat

HI , I am wrirting a script for checking the performance monitoring on Linux System when my application is running. I have to run a test for 30 minutes on some server and while the test is running i have to capture the perfromance metrics of Linux through vmstat , sar, mpstat, free. here is the... (3 Replies)
Discussion started by: Anamica
3 Replies

4. Shell Programming and Scripting

Mpstat and sar

HI I ma using mpstat and sar commands to check the cpu utilisation but the results are not matching .I dont understand why thisis happening? $ sar -u 12 5 Linux 2.6.9-89.35.1.ELhugemem (abcd.efgh.com) 03/07/2013 02:43:16 AM CPU %user %nice %system %iowait %idle... (1 Reply)
Discussion started by: ptappeta
1 Replies

5. Linux

Execution problem wid mpstat command

mpstat -P ALL 1 10 it results.. 08:05:54 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s 08:05:55 PM all 0.00 0.00 0.49 0.00 0.49 0.00 0.00 99.02 1024.75 08:05:55 PM 0 0.00 0.00 0.00 0.00 0.99 0.00 0.00 ... (1 Reply)
Discussion started by: pritesh_patil
1 Replies

6. AIX

topas and mpstat disagree on CPU count

I have a number of LPARs on one P520. All LPARs are running 5.3 and I observe the following: On some LPARs the number of CPUs found do not match between topas and mpstat. Server 1: $ mpstat System configuration: lcpu=4 ent=0.2 mode=Uncapped cpu min maj mpc int cs ics rq ... (1 Reply)
Discussion started by: petervg
1 Replies

7. Solaris

mpstat command

Hi, I would like to clearly understand the output of the mpstat command. What is the mutex spins and also context switches? What if we saw that the number of mutex spins is high. Basically, what to look for in the output of the mpstat command? What is wrong and what is ok. what is the value... (3 Replies)
Discussion started by: Pouchie1
3 Replies

8. Solaris

VMSTAT and MPSTAT anomalies

All: I have a V445 server with four IIIi CPUs and 8 GB RAM running Solaris 10 and an Oracle database along with some app server components and we have had some performance issues - so I collected some VMSTAT and MPSTAT data over the course of three days with a 15-minute polling interval. I... (1 Reply)
Discussion started by: jeffd4d
1 Replies

9. Solaris

Describe the parameters of iostat,vmstat and mpstat

Hi, I am trying to take the Statistics of the machine during load.Can someone explian the parameters of iostat: tty sd1 sd2 sd3 sd4 cpu tin tout kps tps serv kps tps serv kps tps serv kps tps serv us sy wt id vmstat: kthr ... (1 Reply)
Discussion started by: grrajeish
1 Replies

10. UNIX for Advanced & Expert Users

mpstat command

I gave mpstat command in my system.. the o/p is like below CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl 0 199 3 198 112 5 78 95 124 55 0 9 25 14 7 54 1 186 2 97 92 1 45 94 121 41 0 220 27 14 5 54 ... (2 Replies)
Discussion started by: shahnazurs
2 Replies

Featured Tech Videos