Check CPU usage by DB

Here is a script originally written by my friend Jim Baker, which I frequently use to check CPU utilisation on a shared DB server by instance

####################
# topinstance.sh
####################
#!/bin/ksh

DBS=`ps -eo args | grep pmon | grep -v grep | cut -c 10-`
PROCS=/tmp/_$$_procs.txt
ps -eoargs,pcpu > $PROCS

for DB in `echo $DBS`
do
echo `date` $DB `cat $PROCS | grep $DB | grep -v grep | sed ’s/.* *//’ | \
awk ‘BEGIN { totalcpu = 0.0 } { totalcpu += $0 } END { print totalcpu }’
`
done

rm -f $PROCS
#####################

This can then be combined with

####################
# pollstat.sh
####################
#!/bin/ksh
touch /home/users/hilda/hostname_usage.log

while [ true ]
do
/home/users/hilda/topinstance.sh >> /home/users/hilda/hostname_usage.log
sleep 30
done

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

to grab a snapshot every 30 seconds.

This has proven to be useful when combined with AWR reports, so we can quickly determine whether a performance issue is self inflicted within an application, or because some other database is hogging the resource.

No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>