1833491 Members
2864 Online
110052 Solutions
New Discussion

Monitor CPU usage

 
kholikt
Super Advisor

Monitor CPU usage

I need to monitor the CPU usage of the server by writing some shell script. May I know what is the best approach? Should I just use SAR comman and take the average
abc
6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: Monitor CPU usage

Shalom kholit,

Pull the sar command out of this scriptset and you are done:

http://www.hpux.ws/system.perf.sh

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Arunvijai_4
Honored Contributor
kholikt
Super Advisor

Re: Monitor CPU usage

I have written this script but somehow it doesn't work

#!/usr/bin/sh
$IDLE=`sar -u 3 5 | grep Average | awk '{print $5}'`
if [ "$IDLE" -lt "10" ]
then
echo "Warning CPU high"
fi
~
"cpu_mon" 7 lines, 125 characters
root@PUISCEDB31 # ./cpu_mon
./cpu_mon: line 3: =91: command not found
./cpu_mon: line 4: [: : integer expression expected
abc
Carlos Roberto Schimidt
Regular Advisor

Re: Monitor CPU usage

Don´t put value for variable as follow:

$IDLE=`sar -u 3 5 | grep Average | awk '{print $5}'`

Correct is:

IDLE=`sar -u 3 5 | grep Average | awk '{print $5}'`

You use $IDLE instead only IDLE for variable.
Arturo Galbiati
Esteemed Contributor

Re: Monitor CPU usage

Hi,
yoy can use glance in adviser_mode to collect data about resources usage including CPU.
This is a little script I use for thi scope.
(It collects CPU, memory, disk and swap)


GlnCmd=/opt/perf/bin/glance
WrkDir=
GlnSyn=$WrkDir/gln_syntax_file
GlnOpt="-j60 -adviser_only -nosort -iterations 2 -bootup -syntax $GlnSyn"
ResLog=$(date +%Y%m)-res-cop.log
#echo -- MM/DD/YY HH:MM:SS CPU DSK MEM SWA
$GlnCmd $GlnOpt 2>/dev/null |tail +2 >>$WrkDir/../dat/$ResLog

cat $WrkDir/gln_syntax_file
print "-- ",
gbl_statdate,
" ",
gbl_stattime,
" ",
gbl_cpu_total_util|3|0,
" ",
gbl_disk_util_peak|3|0,
" ",
gbl_mem_util|3|0,
" ",
gbl_swap_space_util|3|0


HTH,
Art
Arturo Galbiati
Esteemed Contributor

Re: Monitor CPU usage

Hi,
please, remember to assign point who spent time and affort helping you.
It's only a bit thing but really appreciated.
Art