Tuesday, August 14, 2012

PSOFT : Unix script to monitor number of active client connections & CPU%


Need for Script : This script tracks number of active client connections to peoplesoft domain which are in busy or busy wait state. if there are maximum number of connections then that may slow down the performance of your PS environment if hardware resources are not that strong.
Same was the case with one of our servers where I had to implement a solution to restrict number of active  busy client connections.
Also this script alerts on finding CPU % beyond specified threshold.


#######################################################################################
#!/bin/ksh
#This script monitors number of active client connections in App Server & unix server CPU Utilization
#Author : Niraj Patil
#Platform : AIX 6.1 , PplTools 8.48.19
########################################################################################


DTIME=`date +%Y%m%d%H%M`
LOGFLE=/home/NjServer/myScripts/ConnectionMonitor${DTIME}.log
## Running .profile for Cron
. $HOME/.profile
echo "Beginning script........." > $LOGFLE
EMAIL=`cat /home/NjServer/myScripts/mail`
domname=`echo $USER | tr 'a-z' 'A-Z'` ; export domname
bzcnt=0
cd $PS_HOME/appserv

for bz in `psadmin -c cstatus -d $domname 2> /dev/null | sed -e '1,3 d' -e '/^$/ d' -e '$ d' | awk -F" " '{ print $5 }'`
do
if [ "$bz" = "BUSY" -o "$bz" = "BUSY/W" ]; then
  let bzcnt=$bzcnt+1
fi

#Mail if no. of client connections are > 20
if [ $bzcnt -ge 20 ]; then
  psadmin -c cstatus -d $domname 2> /dev/null | mail -s "Alert:Maximum no of client connections in $domname App Server on `hostname` at `date`" $EMAIL
  echo "Alert:Maximum no of client connections in $domname App Server on `hostname` at `date`" >> $LOGFLE
  break
fi
done
cd -

#Monitor CPU%
percnt=0
for bb in `ps aux | sort -rn +2 | sed '1 d' | awk -F" " '{ printf("%2f\n",$3); }'`
do
let percnt=$percnt+$bb
done
#Mail alert if cpu% is above 85%
if [ $percnt -ge 85 ]; then
ps aux | head -20 | mail -s "`hostname`:CPU_Utilisation reached to ${percnt}% at `date`" $EMAIL
echo "`hostname`:CPU_Utilisation reached to ${percnt}% at `date`" >> $LOGFLE
fi

6 comments:

  1. Thanks for sharing this useful info. Keep updating same way.
    Regards,Siddu online Training

    ReplyDelete
  2. This post is very informative for everybody. I would like to appreciate your work for good accuracy and I got informative knowledge from here....................Please contact us for Oracle Fusion Financials Training

    ReplyDelete
  3. Usually the blog you posted is very useful to us thanks for posting this blog........................Click Here to learn more with regards to Oracle Fusion Financials Training

    ReplyDelete
  4. Thanks for posting the blog. I felt comfortable while reading the post. Keep posting more blogs...................For more details about Spark and Scala Training in Dallas

    ReplyDelete
  5. You have clearly explained about the process thus it is very much interesting and i got more information from your blog. Visit Our Website for more information about Oracle Fusion SCM Training.

    ReplyDelete