Track db2’s memory usage
Here is a script that displays the current memory usage and peak memory usage of an instance and its databases. The script basically used db2pd -dbptnmem and parses out data to make it easy to read and manage. You can upload the data into a spread sheet to do trending. I intend to expand on this and get greater visibility and useability. if anybody has any suggestions or comments please let me know.
Feel free to use the script at your own risk ! (sorry has to have that disclaimer) : getmemoryusage
Here is the script if you want to view it before you download :
#!/usr/bin/ksh # #------------------------------------------------------------------------------------ # Program     : getmemoryusage.sh # Description : The script gets the following memory usage for the instance #             : Max Limit: The DB2 server's upper bound of memory that can be consumed. #             : Current usage: The amount of memory the server is currently consuming. #             : HWM : The peak memory usage that has been consumed since the activation of the database partition #             : Avail. in Current Cached memory: How much of the current usage is not currently being used. # Usage       : ./getmemoryusage.sh # # Author      : Raju Pillai # Date        : 2009-06-05 #----------------------------------------------------------------------------------- # maximum="0" current="0" highest="0" cached="0" keyword="" OutputDir="/home/db2inst5/report" Datetime="`date +%Y-%m-%d-%H:%M:%S`" if [ $(cat $OutputDir/memory_usage.out|wc -l) -lt 1 ] then print "==============================================" >> $OutputDir/memory_usage.out print "Total instance and database memory usage in KB" >> $OutputDir/memory_usage.out print "==============================================" >> $OutputDir/memory_usage.out print " " >> $OutputDir/memory_usage.out awk 'BEGIN { printf "%-20s%20s%20s%20s%20s\n", "Snapshot timestamp", "Max Limit", "Current Usage","High Water Mark", "Avail. in Current"    printf "%-20s%20s%20s%20s%20s\n", "==================", "=========", "=============","===============","======== =========="}' print >> $OutputDir/memory_usage.out fi db2pd -dbptnmem |grep ' KB'| tr -s " " " " > $OutputDir/db2pd-memory.output while read currentline; do   keyword=`print "$currentline" |awk '{ print $1,$2 }'`  if [ "$keyword" = "Memory Limit:" ]       then             maximum=`print "$currentline" |awk '{ print $3 }'`  fi  if [ "$keyword" = "Current usage:" ]       then             current=`print "$currentline" |awk '{ print $3 }'`  fi  if [ "$keyword" = "HWM usage:" ]       then             highest=`print "$currentline" |awk '{ print $3 }'`  fi  if [ "$keyword" = "Cached memory:" ]       then             cached=`print "$currentline" |awk '{ print $3 }'`  fi done < $OutputDir/db2pd-memory.output print "$Datetime" " " "$maximum" " " "$current" " " "$highest" " " "$cached" > $OutputDir/tmp_memory_usage.out awk '{printf "%-20s%20s%20s%20s%20s\n",$1,$2,$3,$4,$5}' $OutputDir/tmp_memory_usage.out >> $OutputDir/memory_usage.out rm $OutputDir/db2pd-memory.output rm $OutputDir/tmp_memory_usage.out