Script to produce report of High Utilization Processes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to produce report of High Utilization Processes
# 1  
Old 03-23-2011
Script to produce report of High Utilization Processes

Hi,

I have requirement to produce a report on high CPU utilization processes and the processes lying on the CPU for long time (Long running queries). The report should append into the files every 3 minutes. I use prstat to pull top 5 and found the following result.
Code:
(USER01)/opt/tuxedo/appsrv_clasuat> prstat -u tuxedo -a -s time -s cpu -n 5 0 1
   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP
  7241 tuxedo    269M  152M sleep   59    0   1:07.36 1.2% cleard/4
 23213 tuxedo    198M   95M sleep   59    0   0:11.15 0.7% cleard/4
 18524 tuxedo    274M  158M sleep   59    0   0:31.10 0.7% cleard/4
 24827 tuxedo    202M  120M sleep   59    0   0:06.46 0.5% WSH/4
 15415 tuxedo    139M   37M sleep   59    0   0:07.45 0.5% cleard/4
 NPROC USERNAME  SIZE   RSS MEMORY      TIME  CPU
    49 tuxedo   7129M 2524M    32%   5:51.53 6.6%

Total: 49 processes, 191 lwps, load averages: 0.46, 0.69, 0.70

Along with this report, I need append the the each tuxedo process (cleard_relcom) for the above process id (7241,23213,18524,24827,24827) in the report as below. Is it possible to produce single report with both of these result?
Code:
(USER01)/opt/tuxedo/appsrv_clasuat> ps -ef | grep -v grep | grep 2775
  tuxedo  2775     1  3 12:18:57 ?       100:01 cleard_relcom -C dom=clasuat2 -g 5 -i 21 -u clauat02 -U /opt/tuxedo/appsrv_clasu
(USER01)/opt/tuxedo/appsrv_clasuat>

I need to merge both the report and append to a file. Can you please help me?

Thina

Last edited by Scott; 03-23-2011 at 05:25 PM.. Reason: Use code tags, please...
# 2  
Old 03-23-2011
Use > to write output to a file
and >> to append to the file

eg:

Code:
$ prstat -u tuxedo -a -s time -s cpu -n 5 0 1 > report.txt
$ ps -ef | grep -v grep | grep 2775 >> report.txt

# 3  
Old 03-24-2011
Hi Chubler_XL,

Thanks for your reply. I need output in the below format. For each process id listed in the prstat command, I need fetch the process detail through ps command and append in the same row of prstat command.

It means, additional column of PROCESS_DETAIL (cleard_relcom -C dom=clasuat2 -g 5 -i 21 -u clauat02) added in each row of the respective process id listed in the prstat command.

Expected output.
Code:
   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP PROCESS_DETAIL
  7241 tuxedo    269M  152M sleep   59    0   1:07.36 1.2% cleard/4     cleard_relcom -C dom=clasuat2 -g 5 -i 21 -u clauat02 -U /opt/tuxedo/appsrv_clasu
 23213 tuxedo    198M   95M sleep   59    0   0:11.15 0.7% cleard/4     cleard_batch -C dom=clasuat2 -g 5 -i 21 -u clauat02 -U /opt/tuxedo/appsrv_clasu
 18524 tuxedo    274M  158M sleep   59    0   0:31.10 0.7% cleard/4     cleard_batch -C dom=clasuat2 -g 5 -i 21 -u clauat02 -U /opt/tuxedo/appsrv_clasu
 24827 tuxedo    202M  120M sleep   59    0   0:06.46 0.5% WSH/4        WSH -C dom=clasuat2 -g 5 -i 21 -u clauat02 -U /opt/tuxedo/appsrv_clasu
 15415 tuxedo    139M   37M sleep   59    0   0:07.45 0.5% cleard/4     cleard_cb -C dom=clasuat2 -g 5 -i 21 -u clauat02 -U /opt/tuxedo/appsrv_clasu   
 NPROC USERNAME  SIZE   RSS MEMORY      TIME  CPU
    49 tuxedo   7129M 2524M    32%   5:51.53 6.6%

Total: 49 processes, 191 lwps, load averages: 0.46, 0.69, 0.70


Last edited by Franklin52; 03-24-2011 at 06:20 AM.. Reason: Please use code tags
# 4  
Old 03-24-2011
How about this:

Code:
addcmdline ()
{
   PID=`echo $1`
   REM=${PID#* }
   PID=${PID% $REM}
   CMD=`ps -p $PID -o cmd | tail -1`
   printf "%-72s%s" "$1" "$CMD"
}
ADD_DET=0
prstat -u tuxedo -a -s time -s cpu -n 5 0 1 | while read
   case "$REPLY" in
       *\ PID\ USER*)
           echo "$REPLY PROCESS_DETAIL"
           ADD_DET=1 ;;
        *\ NPROC\ USER*)
           echo "$REPLY"
           ADD_DET=0 ;;
        *) [ $ADD_DET -eq 1 ] && line=`addcmdline "$REPLY"`
           echo "$REPLY" ;;
    esac
done

Note this uses ps -p 2775 -o cmd to get the command line of a process (2775 in the example). Your ps may have a different code for the -o option, so if it dosn't work check man ps for the correct code to use instead of "cmd".

Last edited by Chubler_XL; 03-24-2011 at 03:45 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help in modifying existing Perl Script to produce report of dupes

Hello, I have a large amount of data with the following structure: Word=Transliterated word I have written a Perl Script (reproduced below) which goes through the full file and identifies all dupes on the right hand side. It creates successfully a new file with two headers: Singletons and Dupes.... (5 Replies)
Discussion started by: gimley
5 Replies

2. UNIX for Advanced & Expert Users

high cpu utilization

good morning. just wanted to ask if there's a way to check what causes the high cpu utilization of a server for the past 2 months? My jffnms report resulted to high utilization for a specific server last month. is there a way to check via a command line? thanks (9 Replies)
Discussion started by: lhareigh890
9 Replies

3. Shell Programming and Scripting

script to check high cpu utilization for java process

Hello Team, I need help in preparing script to check for high cpu utilisation for java process. I have many java process on my system which consumes high cpu so i have to monitor it using script. ---------- Post updated 12-10-10 at 02:21 AM ---------- Previous update was 12-09-10 at... (1 Reply)
Discussion started by: coolguyamy
1 Replies

4. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

5. AIX

Script to identify high CPU usage processes

Hi Guys, I need to write a script capable of identifying when a high cpu utilitzation process. It sounds simple but we are on a AIX 5.3 environment with Virtual CPU's (VP's) and logical CPU's. Please any ideas or tips would be highly appreciated. Thanks. Harby. (6 Replies)
Discussion started by: arizah
6 Replies

6. Shell Programming and Scripting

High CPU Utilization of the script

There is a script which processes the incoming files from a particular directory and sleeps if it doesnt find any. Currently, i have been told that eventhough there are no files to process, the CPU utilization is very high. An independent evaluation by advisory specialist has found this script does... (2 Replies)
Discussion started by: nandu
2 Replies

7. Shell Programming and Scripting

Script with high CPU utilization

Hi All, i have a script that finds the file with .txt .zip .Z .gzip that are 3 days old in directory /abc/def and removes them find /abc/def -name '0*.txt' -mtime +6 -exec rm {} \; find /abc/def -name '0*.zip' -mtime +6 -exec rm {} \; find /abc/def -name '0*.gzip' -mtime +6... (3 Replies)
Discussion started by: mad_man12
3 Replies

8. Shell Programming and Scripting

Unix Script to find and kill a process with high memory utilization

Hi Unix Gurus i am somewhat new to unix scripting so need your help to create a script as below. # This script would find the process consuming memory beyond a certain #limit. if the meemory consumption is more than 100% for a period of 1 # minute for the specific process. the script would... (0 Replies)
Discussion started by: robinforlinux
0 Replies

9. AIX

High CPU utilization

Hi am facing high cpu utilization on my sybase server. I have P550 Number Of Processors: 4 Processor Clock Speed: 1656 MHz CPU Type: 64-bit Kernel Type: 32-bit LPAR Info: 1 65-D837E Memory Size: 7840 MB in topas it shows Name PID CPU% PgSp Owner dataserv 565264 ... (1 Reply)
Discussion started by: vjm
1 Replies

10. Solaris

High CPU Utilization

Good morning, I need some help figuring out what's eating up my cpu. My application can't get enough cpu to do its job. this is a sunfire V440 2CPU's at 1/593 GHZ with 8GB of memory. In the morning hours the box is at less than 3%. I can't figure out what else is using the CPU. We use foglight and... (2 Replies)
Discussion started by: bbouhaik
2 Replies
Login or Register to Ask a Question