Wednesday 15 March 2017

Goldengate Memory Utilization - Script

Automated Script to get Goldengate process Memory Utilization. 

Below script is a Plug and Play tool for getting memory Utilization of Goldengate Process running on HP-UX or Linux Machine. 

For Creating Script in your Environment do vi GG_MemoUtilization.ksh copy and pest below code


#!/bin/ksh

###########################################################
# +----------------------------------------------------------------------------+
# | Technology : Oracle Goldengate                                                 |
# | Orther      : Kamlesh Parmar (Kamleshparmar21@gmail.com)       |
# | FILE          : GG_MemoUtilization.ksh                                         |
# | PURPOSE   : This Script is Useful to get the Memory Utilization of   |
# |               Goldengate Extract and Replicat Process                     |
# | PARAMETERS   : None                                                              |
# | EXAMPLE      : sh GG_MemoUtilization.ksh                                   |
# +----------------------------------------------------------------------------+
###########################################################

###############################
# determine the OS type
###############################
OSNAME=`uname`

case "$OSNAME" in
  "HP-UX")
    echo "OSNAME = $OSNAME"
    ;;
  "Linux")
    echo "OSNAME = $OSNAME"
    ;;
  "*")
    echo "This script has not been verified on $OSNAME"
    exit 1
    ;;
esac

###############################
# set the temp file
###############################
TMPFILE=/tmp/ggmem.tmp
if [ -f $TMPFILE ]
then
  rm -f $TMPFILE
fi

################################
# loop over the gg process types
################################
PROCESSES="extract replicat"

for PROCESS in $PROCESSES
do
FLAG=""
FLAG=`ps -ef | grep $PROCESS | grep -v grep`

if [ -z "$FLAG" ]
  then
    echo
    echo
    echo
    echo "#####################################"
    echo "#---No $PROCESS processes found-----#"
    echo "#####################################"
    echo
    echo
    echo
 else
    echo
    echo
    echo "###########################################################"
    echo "#-------Individual $PROCESS Process Memory Usage--------- #"
    echo "###########i###############################################"
    echo
    case "$OSNAME" in
      "HP-UX")
        UNIX95=1 ps -e -o user,pid,vsz,sz,etime,args | grep -w $PROCESS |grep -v grep > $TMPFILE
        cat $TMPFILE | grep $PROCESS | awk '{ printf "%3.4f %s\n" , $3/1024/1024,"GB   "$8}' | sort -r
        ;;
      "Linux")
        ps -C $PROCESS -O rss > $TMPFILE
        cat $TMPFILE | grep $PROCESS | awk '{print $2/1024/1024, "GB", $12}' | sort -k 2
        ;;
      "*")
        echo "This script has not been verified on $OSNAME"
        exit 1
        ;;
    esac


    echo
    echo
    echo
    echo "#####################################"
    echo "#---Total $PROCESS Process Usage----#"
    echo "#####################################"
    echo
    case "$OSNAME" in
      "HP-UX")
        cat $TMPFILE | grep $PROCESS | awk '{count ++; sum=sum+$3; } END \
          { print "Number of processes      =",count; \
          print "AVG Memory usage/process =",sum/1024/1024/count, "GB"; \
          print "Total memory usage       =", sum/1024/1024,   "GB"}'
        ;;
      "Linux")
        ps -C $PROCESS -O rss > $TMPFILE
        cat $TMPFILE | grep $PROCESS | awk '{count ++; sum=sum+$2; } END \
          { print "Number of processes      =",count; \
          print "AVG Memory usage/process =",sum/1024/1024/count, "GB"; \
          print "Total memory usage       =", sum/1024/1024,  " GB"}'
        ;;
      "*")
        echo "This script has not been verified on $OSNAME"
        exit 1
        ;;
    esac
    rm -f $TMPFILE
  fi
done
echo
echo
exit 0 

No comments:

Post a Comment