Operating System - Linux
1754417 Members
2790 Online
108813 Solutions
New Discussion юеВ

Re: %use cpu %use memory and swap

 
Muguerza
Occasional Contributor

%use cpu %use memory and swap

Gurus Do you have any shell for generate file with information about %use cpu %use memory and swap?
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor

Re: %use cpu %use memory and swap

Hi:

You can parse the output of 'sar -u' and 'swapinfo -tam'.

See the manpages for 'sar(1M)' and 'swapinfo(1M)'.

Regards!

...JRF...
Nitin Kumar Gupta
Trusted Contributor

Re: %use cpu %use memory and swap

You are asking for which OS, if unix which flavour,


I am sending some information for
(1) HPUX
(a) %CPU : /usr/sbin/sar -u 1 10 | awk '/Average/ { print ( $2 + $3 ) }'
(b) %Memory :

#Memory.sh
PROGNAME=`basename $0`
TMP_FILE=/tmp/$PROGNAME.$$
GLANCE=/opt/perf/bin/glance

trap "rm -f ${TMP_FILE}" 1 2 3 15
if [ $# != 1 ]
then
echo "USAGE : ${PROGNAME} monitor_name"
exit 1
else
MON_NAME=$1
fi

echo "${GLANCE} -f ${TMP_FILE} -maxpages 1 -command -iterations 1 1>/dev/null"
${GLANCE} -f ${TMP_FILE} -maxpages 1 -command -iterations 1 1>/dev/null
MemUtil=`cat ${TMP_FILE} | grep Mem | awk '{print $6}' | awk -F% '{print $1}'`

Count=0
TotalMemUtil=0
for MemUtilVal in $MemUtil
do
TotalMemUtil=`expr ${TotalMemUtil} + ${MemUtilVal}`
Count=`expr $Count + 1`
done
CalculatedMemUtil=`expr $TotalMemUtil / $Count`
#echo $CalculatedMemUtil


(c) %SWAP : /etc/swapinfo -t | grep '^total' | awk '{ print $5 }' | sed -e 's/\%//g'


If you want for windows, or other flavour of unix like AIX, SunOS or Linux let me write.

Rgds
-NKG-