Pages

Monday, January 18, 2021

Memory Usage Monitoring script. For SWAP using processes, Golden Gate, Top 20 oracle processes.

crontab

 0,15,30,45 * * * * /software/oracle/oracle/scripts/memory_usage/gg_mem_usage_wrapper.sh

gg_mem_usage_wrapper.sh
#!/bin/bash
WORK_DIR=/software/oracle/oracle/scripts/memory_usage
LOG_FILE=gg_memory.log
RUN_DATE=`date +"%Y%m%d"_"%H%M%S"`

cd ${WORK_DIR}
touch ${LOG_FILE}
echo " " >> ${LOG_FILE}
echo "=================" >> ${LOG_FILE}
echo ${RUN_DATE} >> ${LOG_FILE}
./gg_mem_usage.sh >> ${LOG_FILE}
echo " " >> ${LOG_FILE}
free -m >> ${LOG_FILE}
echo " " >> ${LOG_FILE}

echo "Top 20 Processes" >> ${LOG_FILE}
ps -eo rss,pid,euser,lstart,args:100 --sort %mem | grep -v grep | sort -n | tail -20 | awk '{printf $1/1024 "MB"; $1=""; print }' >> ${LOG_FILE}
echo " " >> ${LOG_FILE}

echo "Top SWAP Using Processes" >> ${LOG_FILE}
echo " " >> ${LOG_FILE}
echo "SWAP Usage from free -m" >> ${LOG_FILE}
free -m | grep Swap >> ${LOG_FILE}
echo " " >> ${LOG_FILE}
echo "SWAP Usage from /proc" >> ${LOG_FILE}
find /proc -maxdepth 2 -path "/proc/[0-9]*/status" -readable -exec awk -v FS=":" '{process[$1]=$2;sub(/^[ \t]+/,"",process[$1]);} END {if(process["VmSwap"] && process["VmSwap"] != "0 kB") printf "%10s %-30s %20s\n",process["Pid"],process["Name"],process["VmSwap"]}' '{}' \; | awk '{print $(NF-1),$0}' | sort -hr | head | cut -d " " -f2- >> ${LOG_FILE}
echo " " >> ${LOG_FILE}

exit

gg_mem_usage.sh
#!/bin/bash
###############################
# determine the OS type
###############################
OSNAME=`uname`
case "$OSNAME" in
  "SunOS")
    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/pmem.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`
  if [ -z "FLAG" ]
  then
    echo "No $PROCESS processes found"
  else
    echo
    echo "#####################################"
    echo "# Individual $PROCESS Process Usage #"
    echo "#####################################"
    case "$OSNAME" in
      "Linux")
        ps -C $PROCESS -O rss > $TMPFILE
        cat $TMPFILE | grep $PROCESS | awk '{print $2/1024, "MB", $12}' | sort -k 2
        ;;
      "SunOS")
        ps -efo vsz,uid,pid,ppid,pcpu,args | grep -v grep | grep $PROCESS > $TMPFILE
        cat $TMPFILE | grep $PROCESS | awk '{print $1/1024, "MB", $8}' | sort -k 2
        ;;
      "*")
        echo "This script has not been verified on $OSNAME"
        exit 1
        ;;
    esac
    rm -f $TMPFILE
    echo
    echo "#####################################"
    echo "#   Total $PROCESS Process Usage    #"
    echo "#####################################"
    case "$OSNAME" in
      "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/count, "MB"; \
          print "Total memory usage       =", sum/1024,  " MB"}'
        ;;
      "SunOS")
        ps -efo vsz,uid,pid,ppid,pcpu,comm | grep -v grep | grep $PROCESS > $TMPFILE
        cat $TMPFILE | awk '{count ++; sum=sum+$1; } END \
          { print "Number of processes      =",count; \
          print "AVG Memory usage/process =",sum/1024/count, "MB"; \
          print "Total memory usage       =", sum/1024,  " MB"}'
        ;;
      "*")
        echo "This script has not been verified on $OSNAME"
        exit 1
        ;;
    esac
    rm -f $TMPFILE
  fi
done
exit

=================
Sample output
=================
20210118_181502
OSNAME = Linux

#####################################
# Individual extract Process Usage #
#####################################
38.7109 MB DPM_I_01
42.125 MB DPM_P_01
41.8672 MB DPM_S_01
70.8867 MB EXT_I_01
78.9297 MB EXT_P_01
361.016 MB EXT_S_01

#####################################
#   Total extract Process Usage    #
#####################################
Number of processes      = 6
AVG Memory usage/process = 105.589 MB
Total memory usage       = 633.535  MB

#####################################
# Individual replicat Process Usage #
#####################################
32.4219 MB REP_I_01
37.2383 MB REP_P_01
34.8789 MB REP_S_01

#####################################
#   Total replicat Process Usage    #
#####################################
Number of processes      = 3
AVG Memory usage/process = 34.8464 MB
Total memory usage       = 104.539  MB

             total       used       free     shared    buffers     cached
Mem:         64175      62568       1607       9373        384      57889
-/+ buffers/cache:       4294      59880
Swap:        10239        122      10117

Top 20 Processes
361.016MB 30432 oracle Sat Jan 16 20:46:19 2021 /software/ogg/1212/extract PARAMFILE /software/ogg/1212/dirprm/ext_s_01.prm REPORTFILE /software/ogg/1212/dirrpt/EXT_S_01.rpt PROCESSID EXT_S_01 USESUBDIRS
371.129MB 30853 oracle Sat Jan 16 20:46:24 2021 ora_ms03_igt
392.086MB 30851 oracle Sat Jan 16 20:46:24 2021 ora_ms02_igt
488.648MB 28170 oracle Sat Jan 16 20:46:05 2021 ora_smon_igt
512.262MB 28454 oracle Sat Jan 16 20:46:10 2021 oracleigt (LOCAL=NO)
607.949MB 28162 oracle Sat Jan 16 20:46:05 2021 ora_mman_igt
682.445MB 28392 oracle Sat Jan 16 20:46:10 2021 oracleigt (LOCAL=NO)
724.746MB 29669 oracle Sat Jan 16 20:46:13 2021 oracleigt (LOCAL=NO)
972.762MB 30606 oracle Sat Jan 16 20:46:19 2021 oracleigt (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
1046.21MB 29663 oracle Sat Jan 16 20:46:13 2021 oracleigt (LOCAL=NO)
1173.61MB 32712 oracle Sat Jan 16 20:46:47 2021 oracleigt (LOCAL=NO)
1208.2MB 20575 oracle Sun Jan 17 09:59:59 2021 oracleigt (LOCAL=NO)
1278.24MB 28830 oracle Sat Jan 16 20:46:11 2021 oracleigt (LOCAL=NO)
1934.22MB 30150 oracle Sat Jan 16 20:46:16 2021 oracleigt (LOCAL=NO)
2697.98MB 28386 oracle Sat Jan 16 20:46:10 2021 oracleigt (LOCAL=NO)
3556.99MB 28390 oracle Sat Jan 16 20:46:10 2021 oracleigt (LOCAL=NO)
5853.8MB 28388 oracle Sat Jan 16 20:46:10 2021 oracleigt (LOCAL=NO)
5938.82MB 28443 oracle Sat Jan 16 20:46:10 2021 oracleigt (LOCAL=NO)
6263.12MB 28298 oracle Sat Jan 16 20:46:10 2021 oracleigt (LOCAL=NO)
6995.96MB 28164 oracle Sat Jan 16 20:46:05 2021 ora_dbw0_igt

Top SWAP Using Processes

SWAP Usage from free -m
Swap:        10239        122      10117

SWAP Usage from /proc
     30649 splunkd                                    49264 kB
      8260 vxconfigd                                  24152 kB


No comments:

Post a Comment