Operating System - HP-UX
1820198 Members
3824 Online
109620 Solutions
New Discussion юеВ

Getting Average Minimum and Maximum CPU utilization of a process

 
SOLVED
Go to solution
Danny Fang
Frequent Advisor

Getting Average Minimum and Maximum CPU utilization of a process

Hi,

I'm attempting to get the % CPU utilization of a running application in terms of its maximum, minimum and average percentages.

I was using "top" to get the %CPU for an application. However, the value keeps changing very quickly and it becomes difficult to get the values over a period of time to calculate the avarage, min or max values.

In using vmstat,may I know what is the unit measurement of averaged CPU? Also, what is the way of capturing the CPU utilization within a time period?

Would greatly appreciate it if anyone could help me out by showing me the proper usage of of these tools
4 REPLIES 4
Raj D.
Honored Contributor
Solution

Re: Getting Average Minimum and Maximum CPU utilization of a process

Hi Danny ,

You can use sar to capture the CPU usage data over a long time.
vmstat for Virtual Memory statistics.
iostat for io statistics.

###########################################
#!/usr/bin/ksh
touch sar_cpu.txt ; touch vmstat.txt ; touch iostat.txt
i=0
while [ $i -le 60 ]
do
sar -u 5 12 >>sar_cpu.txt # 5 second interval .
vmstat 5 12 >> vmstat.txt
iostat 5 12 >> iostat.txt
echo "-----------------------"
i=`expr $i + 1`
done
echo " SAR data collected for 1 hr complete "
echo " CPU Data stored in the file sar_cpu.txt "
echo "Vmstat Data stored in the file vmstat.txt "
echo "iostat Data stored in the file iostat.txt "
echo "------------------------------------"

###########################################

cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Pat Lieberg
Valued Contributor

Re: Getting Average Minimum and Maximum CPU utilization of a process

You can user sar, sa1 and sa2 to collect this information. Do a man on sar and sa1.
Rajesh SB
Esteemed Contributor

Re: Getting Average Minimum and Maximum CPU utilization of a process

Hi,

You can use glance utility to capture periodically.

# glance -f

Using outputfile you can generate CPU report.

Cheers,
Rajesh
Ranjith_5
Honored Contributor

Re: Getting Average Minimum and Maximum CPU utilization of a process

Hi Danny,

I am just go through the script. This will help you to get a consolidated system statistics. If you can configure a mail alias in the server the same statistics can me mailed to your email ID automatically on daily basis.



#script for putting glance output to file - every hour.

#Exporting the required paths

export path=/syam/glance
export file=`date "+glance%d%m%y.txt"`
export data=`date "+/syam/glance/glance%d%m%y.txt"`
/usr/bin/echo "Reading at `date` \n" >> /syam/glance/$file

#Checking if the file exists and date matches file.

if ["$data" == "/syam/glance/$file"] 2>/dev/null
then
/opt/perf/bin/glance -adviser_only -iterations 2 -j2 -syntax /syam/glance/glance.syntax >> /syam/glance/$file
exit 0
else
/opt/perf/bin/glance -adviser_only -iterations 2 -j2 -syntax /syam/glance/glance.syntax >> /syam/glance/$file
exit 0
fi


============================================================================================================================

#Script for calculating min & max value from log files

s1=`ls -ltr /syam/glance/*.txt|tail -2|head -1|awk '{print $NF}'`

#Actual Script starts here

#Calculating min/max/avg values for CPU

echo "Report for DATASVR Server\n" > /syam/glance/DATASVR-stat
Mincpu=`strings $s1|grep -v "0.0"|grep "CPU UTIL"|awk '{print $NF}'|awk 'NR==1 {m=$1} $1<=m {m=$1} END {print m}'`
echo "Min CPU Util - $Mincpu %" >> /syam/glance/DATASVR-stat
Maxcpu=`strings $s1|grep -v "0.0"|grep "CPU UTIL"|awk '{print $NF}'|awk 'NR==1 {m=$1} $1>=m {m=$1} END {print m}'`
echo "Max CPU Util - $Maxcpu %" >> /syam/glance/DATASVR-stat
avgcpu=`strings $s1|grep -v "0.0"|grep "CPU UTIL"|awk '{s+=$NF} END {print s/NR}'`
echo "Avg CPU Util - $avgcpu %" >> /syam/glance/DATASVR-stat
echo "\n" >> /syam/glance/DATASVR-stat

#Calculating min/max/avg values for MEMORY

Minmem=`strings $s1|grep -v "0.0"|grep "MEM UTIL"|awk '{print $NF}'|awk 'NR==1 {m=$1} $1<=m {m=$1} END {print m}'`
echo "Min MEMORY Util - $Minmem %" >> /syam/glance/DATASVR-stat
Maxmem=`strings $s1|grep -v "0.0"|grep "MEM UTIL"|awk '{print $NF}'|awk 'NR==1 {m=$1} $1>=m {m=$1} END {print m}'`
echo "Max MEMORY Util - $Maxmem %" >> /syam/glance/DATASVR-stat
avgmem=`strings $s1|grep -v "0.0"|grep "MEM UTIL"|awk '{s+=$NF} END {print s/NR}'`
echo "Avg MEMORY Util - $avgmem %" >> /syam/glance/DATASVR-stat
echo "\n" >> /syam/glance/DATASVR-stat

#Calculating min/max/avg values for DISK

Mindisk=`strings $s1|grep -v "0.0"|grep "DISK PEAK UTIL"|awk '{print $NF}'|awk 'NR==1 {m=$1} $1<=m {m=$1} END {print m}'`
echo "Min DISK Util - $Mindisk %" >> /syam/glance/DATASVR-stat
Maxdisk=`strings $s1|grep -v "0.0"|grep "DISK PEAK UTIL"|awk '{print $NF}'|awk 'NR==1 {m=$1} $1>=m {m=$1} END {print m}'`
echo "Max DISK Util - $Maxdisk %" >> /syam/glance/DATASVR-stat
avgdisk=`strings $s1|grep -v "0.0"|grep "DISK PEAK UTIL"|awk '{s+=$NF} END {print s/NR}'`
echo "Avg DISK Util - $avgdisk %" >> /syam/glance/DATASVR-stat
echo "\n" >> /syam/glance/DATASVR-stat

#Consolidating the reports to final report file-"final-stat"


strings /syam/glance/DATASVR-stat >> /syam/glance/final-stat
echo "\n" >> /syam/glance/final-stat

======================================================================================================================

#Mailing the report.

mailx -s "Daily Uptime Report DATASVR" MAIL_ALIAS < "/syam/glance/final-stat"

#Putting file in /tmp - In case if you need it again
cp /syam/glance/final-stat /tmp/.

#Sleeping for 20 sec. - waiting to send the mail
sleep 20

#Resetting the file to zero bytes again

> /syam/glance/final-stat


======================================================================================================================================

CRONTAB ENTRIES FOR DATA COLLECTION
======================================
# Running anil1 to collect glance output every hour
0,30 * * * * ksh /syam/glance/anil1
# Calculating daily min/max values from glance file
15 00 * * * ksh /syam/glance/stat

=================================================================================================================================


Regards,
Syam