Operating System - HP-UX
1833346 Members
3441 Online
110051 Solutions
New Discussion

Any other utility can used to check CPU time like "top"?

 
yyghp
Super Advisor

Any other utility can used to check CPU time like "top"?

I am going to write a script to monitor the oracle processes, when one of them continues to consume CPU 100% for about 1000 minutes, then send me an email.
Although "top" can be used to check the current "Raw CPU percentage" ("%CPU") and "Number of system and CPU seconds process has consumed" (TIME) of each process, but I don't know how to use "top" output for scripting.
Is there any other utility like "top" to get the "%CPU" and "TIME" of the process?
Thanks!
11 REPLIES 11
Jeff Schussele
Honored Contributor

Re: Any other utility can used to check CPU time like "top"?

Hi,

The best way to do this would be to leverage MeasureWare to collect data & PerfView to analyze it.
These are purchased products, but are designed to get to the process level much better than anything else.

My 2 cents,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
James R. Ferguson
Acclaimed Contributor

Re: Any other utility can used to check CPU time like "top"?

Hi:

If you would like to capture the output of 'top' into a file use the '-f file' switch and argument. For instance, to capture one snapshot, do:

# top -d 1 -f /tmp/top.output

Otherwise, I suggest using 'ps'. If you leverage the UNIX95 option, the outpuf of the time can be displayed in the format "[dd-]hh:mm:ss" instead of "mmmm:ss". This can make things easier.

Regards!

...JRF...

rmueller58
Valued Contributor

Re: Any other utility can used to check CPU time like "top"?

I've wrote a couple of scripts I put in cron for the same purpose trying to isolate which app, that front ends for an Informix DB that is sucking CPU and memory..

#checkproc -- This script view only user related processes
ps -ef |grep -v informix|grep -v root |grep -v lp|awk '{print $4, $1, $2, $7, $8, $9, $10, $11, $12,$13, $14, $15}' |sort -r| head -10

#chkps.sh
# this file appends information in a log to show High Water Marks through the day. Note Column #3
export line1=`checkproc |head -2 |tail -1`
export line2=`checkproc |head -3 |tail -1`
export line3=`checkproc |head -4 |tail -1`
export line4=`checkproc |head -5 |tail -1`
export line5=`checkproc |head -6 |tail -1`
export d=`date +%D`
export t=`date +%T`
echo $d $t $line1 >> /restore/`date +%Y%m%d`chkproc.log
echo $d $t $line2 >> /restore/`date +%Y%m%d`chkproc.log
echo $d $t $line3 >> /restore/`date +%Y%m%d`chkproc.log
echo $d $t $line4 >> /restore/`date +%Y%m%d`chkproc.log
echo $d $t $line5 >> /restore/`date +%Y%m%d`chkproc.log


it is a way to log it at very least, I use it for troubleshooting a vendor app that periodically gives me headaches.. I've isolated several apps that the vendor was forced to re-write because of this.

Generally the DB is not the problem unless you don't have it tuned correctly.. More likely it is an application with inefficient queries..
yyghp
Super Advisor

Re: Any other utility can used to check CPU time like "top"?

Thanks guys!

Jeff: I don't think I can get it approved to buy an extra product for this purpose, but thanks for your advice!

James: I really don't want to use temporary file for scripting unless I don't have any other choice, that's why I raise the question here. And how "ps" can show the "%CPU" ? ( I need to grep the oracle process keeps consuming 100% CPU ), like this:

CPU TTY PID USERNAME PRI NI SIZE RES STATE TIME %WCPU %CPU COMMAND
4 ? 4243 oracle 239 20 4562M 12460K run 1029:15 100.57 100.40 oracleRMS_PROD

Rex: I read through your script, but where to get "%CPU" ?

Thanks!
Greg Vaidman
Respected Contributor

Re: Any other utility can used to check CPU time like "top"?

if you use the following command line, you can get the top output (mostly) unformatted so that you can parse it inline in a script. This bypasses the temporary file.

TERM=ansi top -d 1 | col -b |
awk '/^CPU[[:space:]]*TTY/,EOF{print}' | tail +2
rmueller58
Valued Contributor

Re: Any other utility can used to check CPU time like "top"?

Column #3 is CPU%
yyghp
Super Advisor

Re: Any other utility can used to check CPU time like "top"?

Hi rex, your script is based on command "ps", but "ps" doesn't get "CPU%", right? So, how can the script shows "CPU%"? Thanks!
Greg Vaidman
Respected Contributor

Re: Any other utility can used to check CPU time like "top"?

ps can get %cpu with the following command line:

UNIX95= ps -e -o ruser,pid,pcpu,args

the 3rd column will be %cpu

see the man page for ps if you need additional columns or want it formatted differently.
yyghp
Super Advisor

Re: Any other utility can used to check CPU time like "top"?

but how I can know that process keeps running more than 1000 mintues?
thanks!
Greg Vaidman
Respected Contributor

Re: Any other utility can used to check CPU time like "top"?

well, you can add cpu to the list of options in the ps command.

but in any case, either with ps or top, the %cpu reported is just for the last scheduling interval. So if you see 100% and 1000 minutes in any one report, it only means that it used 100% over the past couple of seconds. you need to collect data over time and parse it to really say that it used >x% over any period of time.
yyghp
Super Advisor

Re: Any other utility can used to check CPU time like "top"?

I think I'd better use "top" for this purpose, thanks everyone!